我可以隐藏控制器并查看 name cake php 2 吗?
Can i hide controller and view name cake php 2?
我正在使用蛋糕 php 并且由于某些原因我想在 url 中隐藏控制器和动作名称。当前 url 我们喜欢
http://192.168.1.31/home/this_is_test
home 是控制器名称,this_is_test
是动态的 slug。我想要 url 喜欢
http://192.168.1.31/this_is_test。
我的 routes.php 是
Router::connect('/', array('controller' => 'home', 'action' => 'index'));
Router::connect('/dashboard', array('controller' => 'dashboard', 'action' => 'index'));
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
Router::connect('/admin/login', array('controller' => 'users', 'action' => 'login', 'admin' => true));
Router::connect('/contents/*', array('controller' => 'contents', 'action' => 'view'));
Router::connect('/home/*', array('controller' => 'Home', 'action' => 'index'));
我在谷歌搜索后阅读了几个解决方案。还在 routes.php 中尝试过这个。但运气不好
Router::connect(
'/:query',
array('controller' => 'Home', 'action' => 'index',1),
array('query' => '[a-zA-Z]+')
);
如果可能的话,有人知道吗??
你的解决方案
对于静态文本试试这个:
Router::connect('/this_is_test', array(
'controller' => 'home',
'action' => 'this_is_test OR any_other action name'
));
如果是动态的
Router::connect('/:id',
array('controller' => 'home', 'action' => 'index'),
array(
'pass' => array('id'),
array('id' => '[A-Za-z]')
)
);
我希望我知道你真正想要实现的目标。您可以将路线放在最后一个位置。 Here is the reference。
其他选项是为您的控制器使用别名。所以你给你的控制器起了别的名字,为你的控制器设置了一个新的名字,然后在你的路由中调用它。
如果这不起作用,那么您需要编写一个定制组件来帮助您做到这一点。
我正在使用蛋糕 php 并且由于某些原因我想在 url 中隐藏控制器和动作名称。当前 url 我们喜欢
http://192.168.1.31/home/this_is_test
home 是控制器名称,this_is_test
是动态的 slug。我想要 url 喜欢
http://192.168.1.31/this_is_test。
我的 routes.php 是
Router::connect('/', array('controller' => 'home', 'action' => 'index'));
Router::connect('/dashboard', array('controller' => 'dashboard', 'action' => 'index'));
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
Router::connect('/admin/login', array('controller' => 'users', 'action' => 'login', 'admin' => true));
Router::connect('/contents/*', array('controller' => 'contents', 'action' => 'view'));
Router::connect('/home/*', array('controller' => 'Home', 'action' => 'index'));
我在谷歌搜索后阅读了几个解决方案。还在 routes.php 中尝试过这个。但运气不好
Router::connect(
'/:query',
array('controller' => 'Home', 'action' => 'index',1),
array('query' => '[a-zA-Z]+')
);
如果可能的话,有人知道吗??
你的解决方案
对于静态文本试试这个:
Router::connect('/this_is_test', array(
'controller' => 'home',
'action' => 'this_is_test OR any_other action name'
));
如果是动态的
Router::connect('/:id',
array('controller' => 'home', 'action' => 'index'),
array(
'pass' => array('id'),
array('id' => '[A-Za-z]')
)
);
我希望我知道你真正想要实现的目标。您可以将路线放在最后一个位置。 Here is the reference。
其他选项是为您的控制器使用别名。所以你给你的控制器起了别的名字,为你的控制器设置了一个新的名字,然后在你的路由中调用它。
如果这不起作用,那么您需要编写一个定制组件来帮助您做到这一点。