1
votes

I feel like there ought to be, and probably is, an easy solution to this.

The site I'm building will have an admin interface which is where all of the CakePHP functionality will live. The admin interface will generate static files that are then served as the frontend of the site.

I would like all of the admin pages to live under /admin, so...

/admin/users/login
/admin/users/index
/admin/page/edit/x
/admin/module/add

etc, etc.

All of the generated content will live off of / so the only "page" that cannot be created as content is /admin and anything that exists, literally, within the document root (index.php, etc). Basically, I want to avoid polluting the root "directory space" with a bunch of Cake's virtual paths/routes.

I have looked at the Route::connect and associated documentation as well as the HTML link helper docs related to things like "prefix" => "admin" and "admin" => true and I just cannot figure out how to make this work.

In an ideal setup all /admin/fizz/buzz/1 type URLs would execute as though they were actually /fizz/buzz/1 in a plain-vanilla CakePHP deployment, and all of the:

$this->Html->link('label', array('controller' => 'foo', 'action' => 'bar', 3));

helper generated equivalent URLs like /admin/foo/bar/3

How do I go about this?

1

1 Answers

1
votes

To make all controller actions generate and respond to urls starting with /admin either:

move the application

You can just move the whole app i.e. this will work:

DOCUMENT_ROOT
    admin
        app
            controllers
            models
            views
            webroot
        cake
        vendors

Of course, this is better:

app
    controllers
    models
    views
    webroot
cake
vendors
DOCUMENT_ROOT
    admin -> ../app/webroot #symlink

(or any similar solution)

Route based

Or, instead of including the standard routes, define your own:

<?php
// app/Config/routes.php

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

In this way, all routed urls will begin with the string /admin