Jump to content

Recommended Posts

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', '[email protected]', '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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.