leela Posted July 20, 2011 Share Posted July 20, 2011 Hai, I did the posts module in cakephp.Able to add,edit,delete functions.. Now i was trying to add comments to posts already existed.. How to pass post_id ( foreign key to columns table )as hidden to comments_controller -->add() function .. my code is class commentsController extends AppController { var $helpers=array('Html','Form'); var $name='Comments'; function add() { if(empty($this->data)) { $this->set('comment',$this->Comment->read()); } else { if($this->Comment->save($this->data)) { $this->Session->setFlash('The comment for this has been saved'); $this->redirect(array('action'=>'index')); } else { $this->Session->setFlash('Comment is not saved'); } } } } ?> and views/comments/add.ctp is <h2>Add Comments</h2> <?php echo $form->create('Comment',array('action'=>'add'));?> <?php echo $form->input('name');?> <?php echo $form->input('email',array('type'=>'email'));?> <?php echo $form->input('text');?> <?php echo $form->input('post_id',array('type'=>'hidden')) ;?> <?php echo $form->end('Add Comment');?> the url is http://localhost/cakephp/posts/ ----> Id Title Body View Delete Action Action 1 The title This is the post body.sdfsdf View Delete AddComment ViewComment When i click AddComment[/b the url is :::::::: http://localhost/cakephp/comments/add/1 here is the form to add title,text,comment ----------->When i submit ,it is giving ......... SQL Error: 1048: Column 'post_id' cannot be null INSERT INTO `comments` (`name`, `email`, `text`, `post_id`, `created`) VALUES ('ss', 'ss@gmail.com', 'sample text ', NULL, '2011-07-20 11:26:50') Post_id is not passing ............How can i pass this post_id,so that i can do add comment Thanks in advance Link to comment https://forums.phpfreaks.com/topic/242465-how-to-pass-post_id-to-add-comment-as-hidden/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.