General CakePHP Model implementation -


its first cake project , wanna ask basic question somewhing implementations of models

i have objects, users , vehicles.

every user can have 1 vehicle, users table have vehicle_id field.

what want single page can add user and, on same page car

//user model public $belongsto = array(     'vehicle' => array(     'classname' => 'vehicle' ) 

my question is, how add function has /controller/view ?

thank much!

julius

your add function wouldn’t different if managing 1 model; use saveall() instead of save() , save related data too. in case, saveall() save vehicle data user data.

your html form have fields both:

<?php     echo $this->form->begin('user');     echo $this->form->input('user.name');     echo $this->form->input('vehicle.name');     // , on     echo $this->form->end(); ?> 

and process in controller on submission:

<?php class userscontroller extends appcontroller {      public function add() {         if ($this->request->is('post')) {             if ($this->user->saveall($this->request->data)) {                 $this->session->setflash('user , vehicle saved.');                 $this->redirect(array('action' => 'index'));             }         }     } } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -