質問

私は、CakePHPでのルーティングを実装しようとしています。私はこのようなマッピングされたにURLをしたい...

www.example.com/nodes/main - > www.example.com/main www.example.com/nodes/about - > www.example.com/about

だから、この私が私のconfig / 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

を指すようになります
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top