题
我想实现在CakePHP中路由。我想要的URL映射像这样...
www.example.com/nodes/main - > www.example.com/main www.example.com/nodes/about - > www.example.com/about
因此,对于这个我在配置/ routes.php文件的文件中写道..
Router::connect('/:action', array('controller' => 'nodes'));
现在,我得到的东西去,但是当我点击链接,在浏览器的URL看起来像 www.example.com/nodes/main www.example.com/nodes/about
有没有一些方法,我可以得到的URL出现在被送到的方式吗? 在.htaccess设置或httpd.conf中会很容易 - 但我没有访问该
此致 维克拉姆
解决方案
此应该工作:
Router::connect('/main', array('controller' => 'nodes', 'action' => 'main'));
Router::connect('/about', array('controller' => 'nodes', 'action' => 'about'));
您还可以做更强大的东西,像这样的:
$actions = array('main','about');
foreach ($actions as $action){
Router::connect('/$action', array('controller' => 'nodes', 'action' => '$action'));
}
其他提示
基本上,如果你的链接与HTML辅助创建的,具有以下格式:
<?php echo $this->Html->link('your link', array('controller'=>'nodes', 'action'=>'main'));?>
然后,将滤饼转换链接到适当www.example.com/main
但是,如果你的链接是
<?php echo $this->Html->link('your link', '/nodes/main/');?>
它们将指向www.example.com/nodes/main
不隶属于 StackOverflow