行为中的CakePHP控制器名称

行为中的CakePHP控制器名称,cakephp,behavior,Cakephp,Behavior,我创建的关系帖子有很多照片,照片和行为 如何将$data['Photo']['model']='Post'?自动化?我不知道你在问什么,但是当你有一个表单时,你可以简单地向你的$this->data['Photo']['model']添加任何你想要的隐藏字段值 //照片/add.ctp: $this->Form->create('Photo'); $this->Form->input('model', array('type' => 'hidden', 'value

我创建的关系帖子有很多照片,照片和行为


如何将
$data['Photo']['model']='Post'
?自动化?

我不知道你在问什么,但是当你有一个表单时,你可以简单地向你的
$this->data['Photo']['model']
添加任何你想要的隐藏字段值

//照片/add.ctp:

$this->Form->create('Photo');
$this->Form->input('model', array('type' => 'hidden', 'value' =>'yourvalue'));
$this->Form->end('Submit');
使现代化 您可以在表单提交后设置此值,因此即使有人将替换隐藏字段值,您也可以检查它

function add(){
    if(!empty($this->data['Photo']['model']){
       $this->data['Photo']['model'] = "yourvalue";
       $this->Photo->save($this->data));
    }
    else
       rest of the code...
}
    rest of the code

详细解释您的问题…这不是好的解决方案,因为用户可以为隐藏字段设置替换值…您可以在提交表单后在控制器中设置值。