为了提出我的问题,我需要先解释一下我的代码......
我有一个控制器(Controller_App),它扩展了Controller_Template。在控制器的模板视图中,我有jQuery选项卡,带有3个选项卡。当我访问URI:/view/26
时,以下路线开始:
Route::set('view_story', '<action>/<id>(/<stuff>)', array(
'action' => 'view',
'id' => '\d+',
'stuff' => '.*',
))
->defaults(array(
'controller' => 'app',
));
然后在Controller_App中调用以下函数并设置“Explore”jQuery选项卡的URI并使其成为默认选择:
public function action_view($id)
{
$this->template->controller['explore'] = Route::get('explore')
->uri(array(
'controller' => 'explore',
'id' => $id,
));
$this->template->default_tab = 2;
}
这是我的“探索”路线:
Route::set('explore', '<controller>/<id>', array(
'controller' => 'explore',
'id' => '\d+',
))
->defaults(array(
'action' => 'index',
));
问题:
当我尝试使用URL:“myhost.com/view/26”访问故事时,它设置一切正常,但它认为“/ view”是一个目录,因此它会尝试调用“myhost.com/view/”探索/ 26.由于没有名为“view”的控制器,我收到404错误。我通过创建以下路径来解决404错误:
Route::set('explore', '(<directory>/)<controller>/<id>', array(
'directory' => 'view',
'controller' => 'explore',
'id' => '\d+',
))
->defaults(array(
'directory' => '',
'action' => 'index',
));
...然后将我的功能更改为:
public function action_view($id)
{
$this->template->controller['explore'] = Route::get('explore')
->uri(array(
'directory' => '',
'controller' => 'explore',
'action' => 'index',
'id' => $id,
));
$this->template->default_tab = 2;
}
但是当页面加载时,它会调用jQuery.get(),但是它试图调用“/ view”目录下的PHP文件而不是当前目录。
我不知道这是否是一个简单的路由问题,或者我是否甚至吠叫了正确的树。但我已经尝试了所有不同的路线组合,并且不能为我的生活弄清楚这一点。所有建议都表示赞赏!
谢谢, 布赖恩
答案 0 :(得分:0)
Route::uri(...)
生成的uris不是绝对的。
切换到使用Route::url(...)
,你应该很高兴。
Route::url(...)
是将Route::uri(...)
传递给URL::site(...)
的快捷方式。
public function action_view($id)
{
$this->template->controller['explore'] = Route::get('explore')
->url(array(
'controller' => 'explore',
'id' => $id,
));
$this->template->default_tab = 2;
}