【问题标题】:Kohana Undefined property: Request::$actionKohana 未定义属性:Request::$action
【发布时间】:2015-03-05 07:12:54
【问题描述】:

我正在尝试设置我的第一个 Kohana 网页,使用本教程 - http://kohana-tutorial.blogspot.co.uk/2010/10/lesson-1-getting-started.html

按照说明操作后,我得到了这个错误 - Undefined property: Request::$action on line 49。

这是与该行相关的代码,在 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 ?> 

这是由 News.php 调用的,它是渲染某些东西的标准调用。

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

用于解决此错误的程序的完整列表是:

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()

我们将不胜感激。

【问题讨论】:

    标签: php properties undefined kohana


    【解决方案1】:

    本教程已有 4 年历史,所以可能有点过时了。

    使用当前版本的 Kohana,您可以通过以下方式访问受保护的属性 $request->_action

    $this->request->action();
    

    不要犹豫,检查online documentation 甚至system/classes/Kohana 中的源代码,它很清楚并且注释很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-30
      • 1970-01-01
      • 1970-01-01
      • 2014-05-20
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      相关资源
      最近更新 更多