**** Models ****
class User extends AppModel {
var $name = 'User';
var $hasMany = array ('Listing');
}
class Listing extends AppModel {
var $name = 'Listing';
var $belongsTo = 'User';
}
*** Controllers ***
listings_controller
function add() {
$this->set('user',$this->Auth->user()); // From the User Model
Class
if(!empty($this->data)) {
if($this->Listing->save($this->data)) {
$this->Session->setFlash('Your listing has been added');
$this->redirect(array('action' => 'index'));
}
}
}
*** View ***
views/listings/add.ctp
echo $user['User']['username']; /* Passed from listings_controller*/
echo $form->create('Listing');
echo $form->input('title');
echo $form->input('body', array('rows' => '4'));
echo $form->input('user'); <---- How do I pre-populate the
user name here --->
echo $form->end('Save Post');
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---