Kohana 3.1.1 jQuery 选项卡的路由问题
为了问我的问题,我需要先解释我的代码......
我有一个扩展 Controller_Template 的控制器(Controller_App)。在控制器的模板视图中,我有 3 个选项卡的 jQuery 选项卡。当我访问 URI:/view/26
时,将启动以下路由:
Route::set('view_story', '<action>/<id>(/<stuff>)', array(
'action' => 'view',
'id' => '\d+',
'stuff' => '.*',
))
->defaults(array(
'controller' => 'app',
));
然后在 Controller_App 中调用以下函数,并设置“探索”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/” explore/26.由于没有名为“view”的控制器,因此我可以通过创建以下路由来解决 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 文件而不是当前目录,
我不知道这是否是一个简单的路由问题,或者我是否在吠叫正确的树。但我已经尝试了所有不同的路线组合,但我无法弄清楚所有建议,
谢谢 ! 布莱恩
In order to ask my question, I need to explain my code first...
I have a controller (Controller_App) which extends Controller_Template. Inside the controller's template view, I have jQuery tabs with 3 tabs. When I access the URI: /view/26
, the following route kicks in:
Route::set('view_story', '<action>/<id>(/<stuff>)', array(
'action' => 'view',
'id' => '\d+',
'stuff' => '.*',
))
->defaults(array(
'controller' => 'app',
));
The following function is then called in Controller_App and sets the URI of the "Explore" jQuery tab and makes it the default selection:
public function action_view($id)
{
$this->template->controller['explore'] = Route::get('explore')
->uri(array(
'controller' => 'explore',
'id' => $id,
));
$this->template->default_tab = 2;
}
Here is my "explore" route:
Route::set('explore', '<controller>/<id>', array(
'controller' => 'explore',
'id' => '\d+',
))
->defaults(array(
'action' => 'index',
));
The problem:
When I try to access a story with the URL: "myhost.com/view/26", it sets everything okay, but it thinks that "/view" is a directory, so it tries to call "myhost.com/view/explore/26. Since there is no controller called "view", I get a 404 error. I was able to get around the 404 error by creating the following route:
Route::set('explore', '(<directory>/)<controller>/<id>', array(
'directory' => 'view',
'controller' => 'explore',
'id' => '\d+',
))
->defaults(array(
'directory' => '',
'action' => 'index',
));
...and then changing my function to:
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;
}
But when the page loads, it calls jQuery.get() but it's trying to call the PHP file under the "/view" directory instead of the current directory.
I don't know if this is a simple routing issue, or if I'm even barking up the right tree at all. But I've tried all different combinations of routes and can't for the life of me figure this out. All suggestions are appreciated!
Thanks,
Brian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Route::uri(...)
生成uris 不是绝对的。切换到使用
Route::url(...)
你应该可以开始了。Route::url(...)
是通过URL::site(...) 传递
。Route::uri(...)
的快捷方式Route::uri(...)
generates uris which aren't absolute.Switch to using
Route::url(...)
and you should be good to go.Route::url(...)
is a shortcut for passingRoute::uri(...)
throughURL::site(...)
.