gpt4 book ai didi

Kohana param() 不起作用

转载 作者:行者123 更新时间:2023-12-04 23:09:49 24 4
gpt4 key购买 nike

我正在使用 Kohana 3。有谁知道为什么 param('controller') 结果为 NULL。

路由:

Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'page',
'action' => 'index',
));

网址: http://localhost/application/page/index/1
参数调用:
$param = Request::instance()->param('controller');
echo Kohana::debug($param); //results: NULL
$param = Request::instance()->param('action');
echo Kohana::debug($param); //results: NULL
$param = Request::instance()->param('id');
echo Kohana::debug($param); //results: 1

最佳答案

在第 622 行的 reqeuest.php 中查找:

// These are accessible as public vars and can be overloaded
unset($params['controller'], $params['action'], $params['directory']);

// Params cannot be changed once matched
$this->_params = $params;

这就是为什么第 695 行不能返回 controller :
public function param($key = NULL, $default = NULL)
{
return $this->_params[$key];
}

这就是你如何获得 Controller $controller = Request::instance()->controller;$controller = $this->request->controller;如果你在 Controller 里面

关于Kohana param() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3278858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com