Please bear with me as I am a cakephp noob. I have this app that should go to http://www.name.com/complexes/somecomplex/unitnumber. I can correctly get it to advance to http://www.name.com/complexes/somecomplex, but I don’t know how to get the full path to my unit number.
Here is my controller:
class ComplexesController extends AppController {
public $name='Complexes';
public $uses=array('User', 'Complex', 'Unit');
public $layout='pagelayout';
public function view() {
$this->set('complex', strtoupper($this->params['id']));
$c=$this->Complex->find('first', array('conditions'=>array('complex_name'=>$this->params['id'])));
$this->set('complex_data', $c);
}
}
and here is my route
Router::connect('/complexes/:id', array('controller' => 'complexes', 'action' => 'view'));
Where do I write the action for calling up a specific unit? Inside my ‘view’ action or another action called ‘unit’? And how do i tell cake to route to that?
I figured it out! I had to pass an argument, called $unit in my view() function, where I set the conditions to look for the unitnumber that I had entered in the url ($unit). so, my code ended up looking like this:
and in my routes file I added this line:
And it worked!