我有一个用于编辑以前存在的用户配置文件的功能,这里是控制器
class PeoplesController extends AppController
{
public $name = "peoples";
public $helpers = array('Html', 'form', 'Js');
public $components = array('RequestHandler');
public function viewPerson($id = NULL) {
$this->set('person', $this->people->read(NULL, $id));
}
public function editPerson($id = NULL)
{
if(empty($this->data)) {
$this->data = $this->people->read(NULL, $id);
}
else {
if($this->people->save($this->data)) {
$this->Session-setFlash('The profile has been updated');
$this->redirect(array('action'=>'viewPerson', $id));
}
}
}
}
视图输出一个预先填充了先前数据的表单
<h2>Edit Profile</h2>
<?php
echo $this->Form->create('people', array('action'=>'edit'));
echo $this->Form->input('firstName');
echo $this->Form->input('secondName');
echo $this->Form->input('addressOne');
echo $this->Form->input('addressTwo');
echo $this->Form->input('city');
echo $this->Form->input('county');
echo $this->Form->input('country');
echo $this->Form->input('postCode', array(
'label' => 'Zip Code',
));
echo $this->Form->input('dob', array(
'label' => 'Date of birth',
'dateFormat' => 'DMY',
'minYear' => date('Y') - 70,
'maxYear' => date('Y') - 18,
));
echo $this->Form->input('homePhone');
echo $this->Form->input('mobilePhone');
echo $this->Form->input('email', array(
'type' => 'email'
));
$goptions = array(1 => 'Male', 2 => 'Female');
$gattributes = array('legend' => false);
echo $this->Form->radio('gender',
$goptions, $gattributes
);
echo $this->Form->input('weight');
echo $this->Form->input('height');
echo $this->Form->input('referedBy');
echo $this->Form->input('id', array('type'=>'hidden'));
echo $this->Form->end('Edit Profile');
?>
视图似乎工作正常@
http://localhost/Cake/peoples/editPerson/2
但是当我点击提交时,网址更改为
http://localhost/Cake/people/edit/2
所以我改变了
echo $this->Form->create('people', array('action'=>'edit'));
至
echo $this->Form->create('people', array('action'=>'editPerson'));
我尝试将 create 函数的第一个参数更改为 peoples 但由于这是指模型而不是控制器它应该是 people 所以我将其改回
我得到的错误是
Error: PeopleController could not be found.
所以它正在寻找错误的控制器,但我不确定在哪里寻找控制器。
我确实曾经让控制器类名不大写,但我遵循了一些关于约定的建议并将其大写,但我以前的其他功能仍然可以正常工作,所以我认为这不是问题
有什么想法为什么要更改 url 并寻找错误的控制器?