在页面控制器中的CakePHP路由 [英] CakePHP routing in pages controller

查看:125
本文介绍了在页面控制器中的CakePHP路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CakePHP创建了一个网站,我需要为静态页面设置一些URL,这些页面由页面控制器处理。基本上,我想要有两种不同类型的静态页面,URLS

I am creating a site with CakePHP, and I need to set some URLs for static pages, which are handled by the pages controller. Basically I want to have two different types of static pages, with the URLS


mysyte.com/page

mysyte.com/page

应该映射到 app / views / pages / page.ctp


mysite.com/special/page

mysite.com/special/page

这应该映射到 app / views / pages / special-page.ctp 。请注意,在第一种情况下,页面也可以是特殊。

which should map to app/views/pages/special-page.ctp. Note that in the first case page can be 'special' as well.

我有一点失去了我为这种情况设置的路由。我尝试使用这两个路由

I am a bit lost with the routing I have to set up for this situation. I have tried to use the two routes

Router::connect(
    '/special/:mypage',
    array('controller' => 'pages', 'action' => 'display'),
    array('pass' => array('mypage'), 'mypage' => '[a-z]+')
);
Router::connect('/*', array('controller' => 'pages', 'action' => 'display'));

和页面控制器

function display($page = null, $mypage = null) {
    if ($mypage) {
        $path = array('special-'. $mypage);
    }
    else {
        $path = func_get_args();
    }

    //The rest of the display action
}

问题是,似乎:mypage 作为操作中的第一个参数传递,它是 page ,而不是 mypage 参数。

The problem is that is seems that :mypage is passed as the first parameter in the action, which is page, and not as the mypage parameter.


推荐答案

实际上,我发现页面控制器已经处理了这种情况,检查页面和子页面。网址 mysite.com/special/mypage 指向 app / views / pages / special / mypage.ctp 只有规则

Actually I have discovered that the pages controller already handles this situation, checking for page and subpage. The URL mysite.com/special/mypage points to app/views/pages/special/mypage.ctp with the only rule

Router::connect('/*', array('controller' => 'pages', 'action' => 'display'));

这篇关于在页面控制器中的CakePHP路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆