如何让 Kohana 调用特定的控制器?
我的路由设置如下:
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'static',
'action' => 'index',
));
以便输入:
在 Controller_Static 上调用
正如它应该的那样。action_index
但是,当我输入:
我希望它会说“找不到 Controller_Test ”,但是 Kohana 错过了它,我从 Apache 收到一条消息,上面写着“在此服务器上找不到请求的 URL /testkohana4/index.php/test。”
即使当我在 controller
目录下放置一个名为 test.php
的文件,其中包含 Controller_Test
类,我仍然收到 page-not-found 错误。
当我在 URL 中输入特定控制器的名称时,如何让 Kohana 调用该控制器?
My routing is set up like this:
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'static',
'action' => 'index',
));
so that typing in:
calls action_index
on Controller_Static
as it should.
However, when I type in:
I expect it to say "cannot find Controller_Test" but instead, Kohana misses it and I get a message from Apache that says "The requested URL /testkohana4/index.php/test was not found on this server."
Even when I put in a file under the controller
directory called test.php
with the class Controller_Test
in it, I still get the page-not-found error.
How can I get Kohana to call a specific controller when I type its name in the URL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:此答案评论中提供的正确解决方案是将 .htaccess RewriteBase 值更改为
您的路线中存在错误。
(...
开头没有正斜杠 应该是(/...
那些
;
是 URL 中的动态段,因此在此示例中:将导致调用:
这应该对你有用。
Edit: The correct solution as provided in this answers comments was to change the .htaccess RewriteBase value to
There's a mistake in your route. There is no forward slash at the beginning of
(<action> ...
That should be(/<action> ...
Those
<blocks>
are dynamic segments in the URL. So in this example:Would result in this being called:
That should work for you. Hope that helped.