所以我尝试创建一个编辑功能,似乎当我按下编辑按钮时,它会将我重定向到编辑页面,其中包含正确的ID,但所有输入都是空的....任何想法为什么?
public function edit($id=null) {
$user =$this->Users->get($id);
if ( !$this->Users->exists($user) ) {
throw new NotFoundException( __( 'Invalid user' ) );
}
if ( $this->request->is( 'post' ) || $this->request->is( 'put' ) ) {
$user = $this->Users->patchEntity($user, $this->request->data);
$query = $this->Users->find( 'all', array( 'conditions' => array( 'id' => $id) ));
$aros = $query->first()->toArray();
$save = $this->Users->save( $this->request->data );
if ($save) {
$this->Flash->success( 'The user has been saved');
} else {
$this->Flash->error( 'The user could not be saved. Please, try again.');
}}
答案 0 :(得分:1)
你没有粘贴所有必需的代码所以这里有两个猜测:
我建议你在book.cakephp.org上做基础教程,根据粘贴的代码和你想做的事情,看起来你根本不知道它是如何工作的。