I have a User model where each user hasmany posts
Model
class User extends AppModel
{
var $name = 'User';
var $belongsTo = 'Group';
var $hasMany = array( 'Posts' => array( 'className' => 'Post' ) );
}
class Post extends AppModel
{
var $name = 'Post';
var $belongsTo = array( 'User' => array( 'className' => 'User' ) );
}
So on users/profile I can access user details and list of their posts
So far so good.
The problem comes when I try to take data from a form on users/profile
to insert a new post with function add in users_controller
function add()
{
if (!empty($this->params['data']))
{
print_r($this->params['data']); // for debug purposes only
if ($this->Post->save($this->params['data']))
{
$this->set('data', $this->Post->findAll());
$this->render('posts', 'ajax');
}
else
{
// do nothing
}
}
}
Output of $this->params['data']...
Array ( [Post] => Array ( [title] => test title [body] => some random
text as a body ) )
But I get the following error message...
Notice: Undefined property: UsersController::$Post in F:\xampplite
\htdocs\cake\app\controllers\users_controller.php on line 60
Fatal error: Call to a member function save() on a non-object in F:
\xampplite\htdocs\cake\app\controllers\users_controller.php on line 60
Can anyone tell me what I'm doing wrong please.
Thanks in advance
Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---