我正在尝试使用Request::factory()
方法在Kohana的视图文件中回显请求,并且我在该请求中发送了一个我无法进入User
控制器的值这里是我的代码:
查看文件:
<h1> Welcome to My First View File </h1>
<?php echo Request::factory("user",array("id" => 123))->execute(); ?>
然后User.php
控制器有这个代码:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_User extends Controller {
public function action_index()
{
$value = $this->request->param('id');
$content = View::factory('menu')->bind("id", $value);
$this->response->body($content);
}
} // End User
并且视图menu.php
有以下代码:
<h2> This is the view called by Request and Parameters send was:
<?php echo $id; ?>
</h2>
当我运行代码时,它显示文字This is the view called by Request and Parameters send was:
,但它没有显示$id
任何人都可以告诉我原因?
答案 0 :(得分:1)
Here您可以看到,Request::factory()
需要URI
值第一个参数。所以,你应该打电话给:
<h1> Welcome to My First View File </h1>
<?php echo Request::factory(Route::get("user")->uri(array("id" => 123)))->execute(); ?>
或
<h1> Welcome to My First View File </h1>
<?php echo Request::factory("user/123")->execute(); ?>
第一个示例使用reverse routing,其中“user”是Route
名称。我假设您已经Route
处理URI
,例如'/ user / 123'。