开发者

CakePHP input field for age range. Not sure about how to approach this

I am creating an experimental search form with CakePHP, and I am reading the CakePHP manual and studying other tutorials on this subject.

There seems to be a LOT of ways searching is done, and I am trying to decide on the best pattern. In the meantime, coming up with some "unresolvable" questions.

I've read several tutorials and also tried the CakePHPDC search plugin with no luck at all. And most of the tutorials I found keep the query login in the Controller which seems like the model is the appropriate place...

I am a bit lost on all of this, so please any simple guidance or suggestions would be appreciated.

And back to my initial problem:

I am creating the age range input field like -

echo $this->Form->input('Plan.age_id');

BUT the first parameter is treated as the Model.field name: Plan.age_id, so this is the field data that will be gathered.

But my Age table has: min_age and max_age fields. I need to run a comparison on the mi开发者_C百科n and max based on the Plan.age_id data?

I am just not sure if I am approaching this right.

And excuse my ignorance, I am very new to messing with search queries in CakePHP.


Sounds like all you need to do is formulate an appropriate search query from the given data:

$this->Plan->find('all', array(
    'conditions' => array(
        'Plan.min_age <=' => $this->data['Plan']['age_id'],
        'Plan.max_age >=' => $this->data['Plan']['age_id']
    )
));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜