嘿大家我遇到这个问题,当我点击提交时表单没有更新。如果($ this-> request->是(" post")){....}阻止但是它没有更新。
这是代码。
PagesController.php
public function admin_edit($id=NULL){
$this->request->data = $this->Page->find("first",array("conditions"=>array("Page.id"=>$id)));
if($this->request->is('post')){
$this->request->data["Page"]["id"] = $id;
if($this->Page->save($this->data)){
echo "Done";
}
}
}
admin_edit.php
URL -> http://localhost/cakephp_practice/admin/pages/edit/4
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="DataTable">
<tr>
<th>Administrator > Edit Page</th>
</tr>
<tr>
<td>
<?php
echo $this->Form->create('Page', array("action" => "edit", "method" => "Post",'enctype' => 'multipart/form-data', 'id' => 'editPage'));
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"> <span class="require">* Please note that all fields that have an asterisk (*) are required. </span></td>
</tr>
<tr>
<td>Name: <font color="red">*</font></td>
<td align="left"><?php echo $this->Form->text('Page.name', array('maxlength' => '254', 'size' => '20', 'label' => '', 'div' => false, 'class' => "form-inbox required")) ?>
</td>
</tr>
</table>
<table>
<tr>
<td> </td>
<td>
<?php echo $this->Form->submit('Submit', array('maxlength' => '50', 'size' => '30', 'label' => '', 'div' => false)) ?>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<?php echo $this->Form->end(); ?>
</td>
</tr>
</table>
我使用过Configure :: write(&#39; Routing.prefixes&#39;,&#39; admin&#39;);自动解析url,如localhost:// project_name / admin / pages / edit to admin_edit pages controller of action。
编辑:当我print_r($ this-&gt; request-&gt; data)时;在if块中,name字段仍然包含旧值而不是我输入的新值。那是为什么?
答案 0 :(得分:1)
这一行: -
if($this->Page->save($this->data)){
应该是: -
if($this->Page->save($this->request->data)){
但是,您的方法的第一行是覆盖$this->request->data
,其中应包含您的表单数据!