我有子域 www.panel.example.com 和域 www.example.com。
我的 bootstrap.php:
<?php
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
));
Route::set('panel', '(<controller>(/<action>(/<id>)))', array('subdomain' => 'panel'))
->defaults(array(
'directory' => 'panel',
'controller' => 'panel',
'action' => 'index',
'subdomain' => 'panel',
));
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'home',
'action' => 'index',
));
?>
当我在浏览器上写地址时:www.panel.example.com 我有一个错误:
HTTP_Exception_404 [ 404 ]: The requested URL / was not found on this server.
我的结构:
application/classes/controller(域的 Controller )
application/classes/controller/panel(子域的 Controller )
如何正确地做到这一点?
最佳答案
没有内置的方法来处理路由中的子域。所以我的建议来自搜索互联网:
一种方法是从 SERVER
全局获取子域:
list($subdomain) = explode('.', $_SERVER['SERVER_NAME'], 2);
然后,根据这个子域调用路由中的 Controller 或目录:
Route::set('panel', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'directory' => $subdomain,
'controller' => 'panel',
'action' => 'index',
));
或者在处理子域时使用 lambda/回调路由以获得更大的灵 active :http://kohanaframework.org/3.2/guide/kohana/routing#lambdacallback-route-logic
此答案基于对不同的子域使用不同的模板:kohana v3: using different templates for different subdomains
关于php - Kohana 3.2 路由和子域问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7379486/