CakePHP: the right controllers, models, and action structure

I have a simple web application with database tables ordersand productswhich I recycle using CakePHP. There are more, but for simplicity, I use only these two here. In a web application, I would like to be able to search for items, search orders, and complete tasks related to orders, but I am having difficulty setting up and choosing components to use this web application. As an example for my problem, I have the following page. Check out the layout below.

|------------------------------|   
|            My App            | 
|------------------------------|
|Search <--| search order      |
|Orders    | search product    |
|etc.      |                   |
|          |                   |
|          |                   |
|------------------------------|

Figure: shows the left navigation bar and body. The arrow indicates the page we are on.

  • Controllers: for this search page , which controllers should be used? I am default to PagesControllerfor static pages right now, but should this search page use PagesController? I also have ProductsControllerand OrdersControllerthat were created when I created the model Productand Order, but it seems more appropriate to use a completely new controller, perhaps, one of them called SearchController. This way, the URL remains below myapp/search/...and does not move everywhere. Is it correct? (I know that I can rewrite URLs, but for later versions)

  • : Product Order. . , ? , , . , , CakePHP, .

  • ( 1 2) , , , ?

+3
3

TL;DR:

- . , SearchesController ProductsController OrdersController ( PagesController).

SearchesController. . , "Views/Searches/", / css javascript /css/searches /js/searches/ ( , ).

(Models/Search.php) , : public $useTable = false; [details] , searches.

SearchController, function orders() function products(), $this->loadModel('Order'); [details], , SearchesController, .

" , ", - - :

$opts = array('limit'=>5);
$orders = $this->Order->search($string, $opts);

Order ( ) ( - ):

public function search($string = null, $opts = null) {
    $params = array();
    $params['limit'] = 10; //sets default
    if(!empty($opts['limit'])) $params['limit'] = $opts['limit'];
    //... build options, contains, limits...etc
    return $this->find('all', $params);
}

- , , ... .. , , , .

+1

. var $uses = array('Order', 'Product');, .

$this->Order->find() $this->Product->find()

+1
  • . (, "" ) "" . , //
  • , ,
  • , Cake, , . , ( ) , , .
0
source

All Articles