당신이 언급 한 페이지에서 코드를 수집 :
제약 : 당신의 컨트롤러 액션에서
$subdomain = substr(env("HTTP_HOST"), 0, strpos(env("HTTP_HOST"), "."));
if(strlen($subdomain)>0 && $subdomain != "m") {
Router::connect('/tips',array('controller'=>'mobiles','action'=>'tips'));
Router::connect('/foo', array('controller'=>'mobiles','action'=>'foo'));
Configure::write('Site.type', 'mobile');
}
/* The following is available via default routes '/{:controller}/{:action}'*/
// Router::connect('/mobiles/tips',
// array('controller' => 'mobiles', 'action'=>'tips'));
// Router::connect('/mobiles/foo',
// array('controller' => 'mobiles', 'action'=>'foo'));
:이 설정에서 tips
또는 foo
라는 컨트롤러
/config/routes.php
에서 가질 수 없습니다 :
$site_is_mobile = Configure::read('Site.type') ?: '';
<?php
if ($site_is_mobile) {
// $html will take care of the 'm.example.com' part
$html->link('Cool Tips', '/tips');
$html->link('Hot Foo', '/foo');
} else {
// $html will just output 'www.example.com' in this case
$html->link('Cool Tips', '/mobiles/tips');
$html->link('Hot Foo', '/mobiles/foo');
}
?>
이 당신의 뷰의 오른쪽 링크 (나는 방법을 보여 드리겠습니다 약간의도 적은 코드를 작성하는) 출력을 허용하지만 $html
도우미가되지 않습니다 : 그런 다음보기에서
다른 영역에 컨트롤러 - 액션 라우트를 사용할 수 있습니다. m.example.com
과 www.example.com
은 $html
도우미와 관련된 다른 도메인입니다.
<?php
$site_is_mobile = Configure::read('Site.type') ?: '';
if ($site_is_mobile !== '') {
$tips_url = '/tips';
$foo_url = '/foo';
} else {
$tips_url = '/mobile/tips';
$foo_url = '/mobile/foo';
}
// make "urls" available to the View
$this->set($tips_url);
$this->set($foo_url);
?>
을 그리고보기에 당신은 사이트가되고 있는지 확인에 대해 걱정할 필요가 없습니다 :
지금, 당신이 원하는 경우에 당신은 당신의보기 떨어져 몇 가지 논리를 적용하려면 컨트롤러에서 다음을 수행 할 수 있습니다 m.example.com/tips
또는 www.example.com/mobile/tips
를 통해 액세스 : Mark Story's article on custom Route classes
에 CakePHP는 - 1.3에서 고급 라우팅을 위해
<?php echo $html->link("Get some kewl tips", $tips_url); ?>
참조저희에게 알려주십시오;)
내 대답을 볼 때마다 그것이 작동하지 않는다면 의견을 말하십시오. 그래서 우리는 확실한 대답을 향해 나아갈 수 있습니다. 이 질문은 많은 사람들에게 도움이 될 수 있습니다. – Oerd