【发布时间】:2013-10-31 15:17:03
【问题描述】:
我是 cakephp 新手。我遵循了这个http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html 教程,当我单击编辑链接时,除了“编辑方法”之外,一切都工作正常,它会给出以下警告消息并且不进行编辑。
Warning (2): strtolower() expects parameter 1 to be string, array given [CORE/Cake/Network/CakeRequest.php, line 471]
Code Context
$type = array(
(int) 0 => 'post',
(int) 1 => 'put'
)
$this = object(CakeRequest) {
params => array(
'plugin' => null,
'controller' => 'posts',
'action' => 'edit',
'named' => array([maximum depth reached]),
'pass' => array(
[maximum depth reached]
)
)
data => array()
query => array()
url => 'posts/edit/2'
base => '/cake_2_0'
webroot => '/cake_2_0/'
here => '/cake_2_0/posts/edit/2'
}
strtolower - [internal], line ??
CakeRequest::is() - CORE/Cake/Network/CakeRequest.php, line 471
PostsController::edit() - APP/Controller/PostsController.php, line 48
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE/Cake/Controller/Controller.php, line 485
Dispatcher::_invoke() - CORE/Cake/Routing/Dispatcher.php, line 186
Dispatcher::dispatch() - CORE/Cake/Routing/Dispatcher.php, line 161
[main] -
【问题讨论】:
-
张贴一些来自
PostsController.php的代码应该在function edit()内 -
公共函数编辑($id = null) { if (!$id) { throw new NotFoundException(__('Invalid post')); } $post = $this->Post->findById($id); if (!$post) { throw new NotFoundException(__('Invalid post')); } if ($this->request->is(array('post', 'put'))) { $this->Post->id = $id; if ($this->Post->save($this->request->data)) { $this->Session->setFlash(__('你的帖子已更新')); return $this->redirect(array('action' => 'index')); }
-
$this->Session->setFlash(__('无法更新您的帖子。')); } if (!$this->request->data) { $this->request->data = $post; } }
-
代码应该出现在问题中!顺便说一句,请始终提及您的确切 CakePHP 版本! (提示:问题与您使用的版本有关)
-
感谢它确实与版本有关的帮助。它实际上解决了我的问题。我正在使用 2.2 版本并遵循教程 2.4!
标签: cakephp