该模型
class CompanyCategory extends AppModel
{
public $name = "CompanyCategory";
public $hasMany = array(
"Company"
);
}
控制器
public function admin_edit($id = null){
//debug($this->request);
//exit(0);
if($id == null){
$this->Session->setFlash("ID categorie eronat!", "flash/simpla_error");
$this->redirect("index");
}
if($this->request->is('post')){
if($this->CompanyCategory->save($this->request->data)){
$this->Session->setFlash("Categoria a fost salvata!", "flash/simpla_success");
}
else{
$this->Session->setFlash("Categoria NU a fost salvata!", "flash/simpla_error");
}
}
else{
$this->Session->setFlash("READ!", "flash/simpla_error");
$this->request->data = $this->CompanyCategory->read(null, $id);
}
}
风景
<div class="content-box">
<div class="content-box-header">
<h3>Editeaza categorie firme</h3>
</div>
<div class="content-box-content">
<?php
echo $this->Form->create("CompanyCategory", array(
'inputDefaults' => array(
'error' => array(
'attributes' => array(
'wrap' => 'span',
'class' => 'input-notification error png_bg'
)
)
)
));
?>
<?=$this->Form->input('id', array('type' => 'hidden'))?>
<?=$this->Form->input('title', array('class' => "text-input small-input", 'label' => 'Denumire'))?>
<?=$this->Form->submit('Salveaza', array('class' => "button"))?>
</div>
</div>
我的问题是提交表单时,控制器为 request->is('false'); 返回 false;
如果我在视图中明确设置 create 方法中的表单助手类型为“post”,它会按预期工作。
当表单方法已经发布而没有设置它时,这有点令人沮丧。
难道我做错了什么 ?