4

I am new to cakephp. I followed this http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html tutorial, everything is working fine apart from the "edit method" when I click the edit link it gives following warning message and does not edit.

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] - 
5
  • Post some of the code from the PostsController.php that should be inside the function edit() Commented Oct 31, 2013 at 15:29
  • public 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(__('Your post has been updated.')); return $this->redirect(array('action' => 'index')); } Commented Oct 31, 2013 at 15:56
  • $this->Session->setFlash(__('Unable to update your post.')); } if (!$this->request->data) { $this->request->data = $post; } } Commented Oct 31, 2013 at 15:56
  • Code should go in the question! btw, please always mention your exact CakePHP version! (hint: the problem is related to the version you are using) Commented Oct 31, 2013 at 15:56
  • Thanks for the help it indeed concerns with the version. It actually solved my problem. I am using 2.2 version and following tutorial 2.4! Commented Oct 31, 2013 at 16:20

1 Answer 1

11

To clear this up a little further, it's the

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

call causing the problem, as CakeRequest::is() has only been able to take an array as of CakePHP 2.4.0, earlier versions are expecting a string.

I'm not sure whether one should expect the tutorials to be compatible to older versions, however, for the sake of completeness, in older versions you'd have to use multiple calls to CakeRequest::is():

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

See also

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.