Cakephp博客教程错误

时间:2013-10-31 15:17:03

标签: cakephp

我是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] - 

1 个答案:

答案 0 :(得分:11)

要进一步澄清这一点,那就是

$this->request->is(array('post', 'put'))

调用导致问题,因为CakeRequest::is()从CakePHP 2.4.0起只能使用array,早期版本需要string

我不确定是否应该期望教程与旧版本兼容,但是,为了完整起见,在旧版本中,您必须使用多次调用CakeRequest::is()

$this->request->is('post') || $this->request->is('put')

另见