php - CakePHP maintain ID even when changing views -
how maintain passed id of form form? instance have http://192.168.6.253/computers/brands/table/4 displays records brands belongsto computers condition computer_id=4. have add() directs me http://192.168.6.253/computers/brands/add.
my problem want retain computer_id=4 when add new brand save brand.computer_id in db. want http://192.168.6.253/computers/brands/add/4 also.
here how call add() in view
echo $this->html->link('add brands here', array( 'controller' => 'brands', 'action' => 'add')) ); here how call table brand in computers view
echo $this->html->link('p',array('action' => '../brands/table', $computer['computer']['id'])); and brand add() , table() controller
public function table($id = null){ if (!$id) { throw new notfoundexception(__('invalid post')); } $this->paginate = array( 'conditions' => array('brand.computer_id' => $id), 'limit' => 10 ); $data = $this->paginate('brand'); $this->set('brands', $data); } public function add() { if ($this->request->is('post')) { $this->brand->create(); if ($this->brand->save($this->request->data)) { $this->session->setflash(__('your post has been saved.')); $this->redirect(array('action' => 'index')); } else { $this->session->setflash(__('unable add post.')); } } }
echo $this->html->link('add brands here' , array( 'controller' => 'brands' , 'action' => 'add' , 4 // or whatever variable, maybe $computer['computer']['id'] ? ) ); ... should trick.
it's snippet used make other link. echo $this->html->link('p',array('action' => '../brands/table', $computer['computer']['id']));
the key point remember in making numerical "ids" @ end, add non-indexed item array. cakephp tack 'em on end.
of course, i'll have warn adding "4" @ end doesn't make sense rest perspective. maybe you're better off using named parameters, this...
echo $this->html->link('add brands here' , array( 'controller' => 'brands' , 'action' => 'add' , 'computer_id' => 4 // or whatever variable, maybe $computer['computer']['id'] ? ) ); ... or query string params...
echo $this->html->link('add brands here' , array( 'controller' => 'brands' , 'action' => 'add' , '?' => array('computer_id' => 4) // or whatever variable, maybe $computer['computer']['id'] ? ) ); take read more in-depth @ http://book.cakephp.org/2.0/en/development/routing.html
Comments
Post a Comment