Kohana 3.1.1 Routing problem with jQuery tabs
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
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 passing Route::uri(...)
through 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;
}
精彩评论