문제

I want to create a Advance Search, something like this:

  • Textbox: Find
  • Dropdown: search by: name, location or telephone
  • Dropdown: Order By Asc or Dec
  • Dropdown: Sort by name, location or telephone
  • Dropdown: Search between dates (if selected)

What is the proper way to add those parameters in the function for the model?

I have came up with this solution:

class ShopsModel extends Model {

  findBy($find, $searchBy, $order, $sort, $betweenDate) {
   // some MySQL query here...
  }

}

Edit: I am talking about the variables - findBy($find, $searchBy, $order, $sort, $betweenDate) - do I need all those parameters or is there alternative solution?

도움이 되었습니까?

해결책

Your solution seems to be ok. But you can also use decorator pattern, so you could make the following query:

$shops = new ShopsModel();
$results = $shops->search('name', 'Tadeck')
    ->order_by('name', 'asc')
    ->between_dates('2012-02-01', '2012-03-14')
    ->fetch_all();

다른 팁

I think what you are describing ought to be done in conjunction with a javascript library like knockoutjs or backbonejs.

Nettuts has covered knockoutjs and a demonstration is available here: http://nettuts.s3.amazonaws.com/1034_ko/demo/index.html

If you are using a pattern like Yii,you can google for tutorials like this one http://aiao.be/2012/01/29/knockout-js-with-the-yii-framework-hello-world-example/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top