This is one =>
echo $this->Html->link('Edit',
array('controller'=>'comments','action'=>'edit',$comment['Comment']['id']));
This is another one in form =>
echo $this->Form->create('Comment',
array('url'=>array('controller' => 'comments', 'action' =>'add', $listposts['Post']['id']) )
);
echo $this->Form->input('post_id',array('type'=>'hidden','style'=>'width:30%','value'=>$listposts['Post']['id']));
echo $this->Form->input('name',array('style'=>'width:30%'));
echo $this->Form->input('email',array('style'=>'width:30%'));
echo $this->Form->input('body',array('rows'=>'5'));
echo $this->Form->end('Submit');
Is it possible to do echo $this->Form->create like the previous one ? Why do i need ‘url’=>array(..) why not like this =>
echo $this->Form->create('Comment',array('controller' => 'comments', 'action' =>'add', $listposts['Post']['id']));
The reason for that is tthat the url-array is an argument in the link()-function of the HTML-helper. If you take a look at the declaration:
So you pass the url as second argument without the
$urlname as you would do with other methods.Howerver, the declaration of the create()-method in the Form-helper is:
Notice that there is just one $options-array. So your url here is a member of an array rather then a member of an argument list. In associative arrays you can’t simply leave the keys so using the url-array without explicitly naming the key should not work.
For more information see the Docs for this methods:
HTML->link()
Form->create()