繁体   English   中英

CakePHP问题:这两个路由之间有什么区别?

[英]CakePHP question: What's the difference between these two routing?

这是一个=>

echo $this->Html->link('Edit',
                            array('controller'=>'comments','action'=>'edit',$comment['Comment']['id']));

这是另一种形式=>

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');

是否有可能像上一个那样回显$ this-> Form-> create? 为什么我需要'url'=> array(..)为什么不喜欢这个=>

echo $this->Form->create('Comment',array('controller' => 'comments', 'action' =>'add', $listposts['Post']['id']));

这样做的原因是,URL数组是HTML帮助器的link()函数中的一个参数。 如果您看一下声明:

link(string $title, mixed $url = null, array $options = array(),  
     string $confirmMessage = false)

因此,就像使用其他方法一样,您将url作为第二个参数传递而没有$url名称。

但是,Form-helper中的create()方法的声明为:

create(string $model = null, array $options = array())

注意,只有一个$ options-array。 因此,这里的url是数组的成员,而不是参数列表的成员。 在关联数组中,您不能简单地保留键,因此在未明确命名键的情况下使用url-array应该不起作用。

有关更多信息,请参阅此方法的文档:
HTML-> link()
表格->创建()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM