开发者

CakePHP route keeps going back to /

I am trying to connect /admin/ to a static page 'admin.ctp'.

I copied the pages controller for modification and copied the display function to admin_display. I also tried creating an admin_index function without parameters. My route looks like this at this moment:

Router::connect('/admin/', array('controller' => 'pages', 'action' => 'index', 'prefix' => 'admin'));

my admin_index function looks like this:

    function admin_index() {
        $page = 'admin';
        $subpage = null;
        $title_for_layout = 'Admin';
        $this->set(compact('page', 'subpage', 'title_for_layout'));
        $this->render('/admin');
    }

I put admin.ctp in /views/pages/ and in /views/pages开发者_开发知识库/admin/

Anyway. When I go to /admin/ it redirects me to /. But when I delete admin_index, it complains that the function does not exist, so I does look for it.

Help?

edit: Big correction, all my admin urls go back to / edit2: resolved it, something with appcontroller :$


Create admin_index.ctp file in /views/pages/.

Remove $this->render('/admin'); from the admin_index function. (If you wanted to use admin.ctp, I think all you would have to do is to remove the / from the argument). There's no reason to render admin.ctp for admin_index, since it's natural for cake to render admin_index.ctp for admin_index function. You just don't gain anything by not doing that the cake way.

If it doesn't work, try

Router::connect('/admin/', array('controller' => 'pages', 'action' => 'index', 'prefix' => 'admin', 'admin' => true));

If you want to route /admin/*action* requests to pages controllers admin_action function, then add this line to routes.php:

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


Router::connect('/admin/', array('controller' => 'pages', 'action' => 'index', 'admin')); would work with the standard pages controller

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜