Search code examples
phppropertiesundefinedkohana

Kohana Undefined property: Request::$action


I'm trying to set up my first Kohana web page, using this tutorial - http://kohana-tutorial.blogspot.co.uk/2010/10/lesson-1-getting-started.html

After following the instructions, I am left with this error - Undefined property: Request::$action on line 49.

This is the code related to that line, in DefaultTemplate.php

48   if (!$view){
49       $view = 'pages/'.$this->request->controller().'/'.$this->request->action.'_tpl';
50     }
51     $this->template->content = View::factory($view, $this->data);
52   }
53 }
54 ?> 

This is called by News.php, which is a standard call to render something.

class Controller_News extends Controller_DefaultTemplate {
    public function  __construct(\Request $request, \Response $response) {
        parent::__construct($request, $response);
    }
    public function action_index(){
        $this->render();
    }
}

The complete list of programs used to get to this error is :

APPPATH/classes/Controller/DefaultTemplate.php [ 49 ] » Kohana_Core::error_handler(arguments)
APPPATH/classes/Controller/News.php [ 13 ] » Controller_DefaultTemplate->render()
SYSPATH/classes/Kohana/Controller.php [ 84 ] » Controller_News->action_index()
{PHP internal call} » Kohana_Controller->execute()
SYSPATH/classes/Kohana/Request/Client/Internal.php [ 97 ] » ReflectionMethod->invoke(arguments)
SYSPATH/classes/Kohana/Request/Client.php [ 114 ] » Kohana_Request_Client_Internal-    >execute_request(arguments)
SYSPATH/classes/Kohana/Request.php [ 997 ] » Kohana_Request_Client->execute(arguments)
DOCROOT/index.php [ 118 ] » Kohana_Request->execute()APPPATH/classes/Controller/News.php [ 13 ] » Controller_DefaultTemplate->render()
SYSPATH/classes/Kohana/Controller.php [ 84 ] » Controller_News->action_index()
{PHP internal call} » Kohana_Controller->execute()
SYSPATH/classes/Kohana/Request/Client/Internal.php [ 97 ] » ReflectionMethod->invoke(arguments)
SYSPATH/classes/Kohana/Request/Client.php [ 114 ] » Kohana_Request_Client_Internal->execute_request(arguments)
SYSPATH/classes/Kohana/Request.php [ 997 ] » Kohana_Request_Client->execute(arguments)
DOCROOT/index.php [ 118 ] » Kohana_Request->execute()

Any help would be gratefully recieved.


Solution

  • This tutorial is 4 years old, so it is probably a little outdated.

    With current version of Kohana, You can access to the protected property $request->_action with the following:

    $this->request->action();
    

    Don't hesitate to check the online documentation or even the source code in system/classes/Kohana, which is clear and well commented.