hi guys,... 
what I'm doing is creating comments for every blog post,...and I need to 
pass blog post ID to a comments table and having problem: Undefined 
variable id in CommentsComtroller.php 

this is my Model: 
<?php
class Comment extends AppModel {
   public $name = 'Comment';
   public $belongsTo = array('User', 'Post');
}
?>

and this is my CommentsController.php action 

<?php
class CommentsController extends AppController {
  var $name = 'Comments';

    public $uses = array('Post', 'Comment', 'User');
    public $helpers = array('Html', 'Form');
    public $components = array('Session');

public function isAuthorized($user) {

    if ($this->action === 'add') {
        return true;
    }

    return parent::isAuthorized($user);
}

    public function add() {

    if(!($post = $this->Post->findById($id)))

        if ($this->request->is('post')) {
        $this->request->data['Comment']['user_id'] = 
$this->Auth->user('id');

        $this->request->data['Comment']['post_id'] = $post['Post']['id']; 
 // HOW CAN I IDENTIFY POST ID FROM PostsController.php    ????? //

            $this->Comment->create();
            if ($this->Comment->save($this->request->data)) {
                $this->Session->setFlash('Your comment has been saved.');

                $this->redirect(array('controller' => 'posts', 'action' => 
'index'));
            } else {
                $this->Session->setFlash('Unable to add your post.');
            }
        }
    }


can anyone help...? 

thanks in advance 

-- 
Like Us on FacekBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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].
Visit this group at http://groups.google.com/group/cake-php?hl=en.


Reply via email to