Question

url: /contents/view/chapter:models/section:associations

class ContentsController extends AppController {
     function view() {
          $this->params['named'];
     }
}

For example, I have the url and controller above and the goal is to use the key/value information from the url to query a database. How would I create a model to do this?

Was it helpful?

Solution

You need to use the passedArgs array:

url: /contents/view/chapter:models/section:associations

class ContentsController extends AppController {
         function view() {
              $foo = $this->Foo->find(
                  array('chapter'=>$this->passedArgs['chapter'],
                        'section'=>$this->passedArgs['section']));
         }
    }

This is available as a part of Cake 1.2, or with the following additions:

Cake PHP - Passing Named Parameters

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top