开发者

How to Create 'Virtual Field' in CakePHP ver. 1.2

BELOW IS JUST AN UNDERSTANDABLE EXAMPLE TO MY PROBLEM

"I have a table nam开发者_开发百科ed 'homes' linked to model 'Home' having fields id,title,price.

I want to create a virtual field named 'calculated_price' which is based on some complex calculation which varies for USER TO USER depending on the search conditions for a particular record.

After that I want to paginate the model 'Home' using

$this->paginate('Home',array('order'=>'calculated_price ASC'));

"

I have an ongoing enhancement project which use Cake version 1.2 that do not support 'virtual_field' concept as supported by Cake Ver 1.3

So please provide a solution to this....

How do I paginate & 'order by' a field which created dynamically using cakephp $this->paginate();

How/Can we tweak cake 1.2 to support virtual field concept of cake 1.3 ?OR is there any better solution?


If the calculation is made on runtime for each visualization why don't you just use $this->set('calulated_price'=>calculated_price); ?


The only solution:

Create a "non-virtual" field in the users table, where you calculate the price via model callback methods e.g. afterSave()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜