views:

309

answers:

1
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?

+1  A: 

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

Doug Hays
So is "Foo" the model?
donalg d
Yes. You could just use the Contents model, assuming your db name and all that is the same. My question is this: is there any different between Controller::passedArgs[index] and Controller::params['named'][index]?
Travis Leleu
No, I don't believe there is. I'm just lazy and prefer using passedArgs
Doug Hays