Submodels in Alloy

31 views
Skip to first unread message

A387

unread,
May 8, 2012, 10:02:32 AM5/8/12
to Alloy
I just read a previous topic about submodules and the just of
underscores to access them. (http://groups.google.com/group/alloyphp/t/
10b18c9b55b7c992) However, it doesn't seem to work, is that because of
an update later on?

URL: http://www.alloy.dev/admin_admpages/
Response:

Module 'admin_admpages' not found
Array
(
[u] => admin_admpages/
[module] => admin_admpages
[format] => html
[action] => index
[route] => module
)

Ideally I'd like to access the CMS / adminpanel via /admin/ is that
possible with the current routing class?

Thanks in advance for your help!

Vance Lucas

unread,
May 8, 2012, 10:57:02 AM5/8/12
to allo...@googlegroups.com
That URL/module should work, and will map to the namespace/file: "Admin\Admpages\Controller". Please ensure that your module is in the right place with the right name, class, and namespace.

Also - The URL you gave is not web-accessible, so I can't see the error :).

--
Vance Lucas

Adri Kodde

unread,
May 8, 2012, 11:03:19 AM5/8/12
to allo...@googlegroups.com
You are right, I messed up with the Controllers namespace!

However the idea with the underscores is not really neat from a user point of view, I think.
Can I make it work like this: /admin/pages -> Admin\Pages\Controller with the current Router class?

8 mei 2012 16:57
That URL/module should work, and will map to the namespace/file: "Admin\Admpages\Controller". Please ensure that your module is in the right place with the right name, class, and namespace.

Also - The URL you gave is not web-accessible, so I can't see the error :).

--
Vance Lucas



On Tuesday, May 8, 2012 9:02:32 AM UTC-5, A387 wrote:
8 mei 2012 16:02

Vance Lucas

unread,
May 8, 2012, 11:21:15 AM5/8/12
to allo...@googlegroups.com
Yes, you can use the router to map any arbitrary URL route to any module/action you want. The admin routes you want could be handled like this, with an 'afterMatch' route callback that modifies the returned parameter array:


// Admin Routes
// ===========================================

// 'afterMatch' callback to prepend 'admin_' to module name
// @return array of $params
$adminPrepend = function($params, $method, $uri) {
    // Prepend 'admin_' to specified 'module' param from route
    $params['module'] = 'admin_' + $params['module'];
    return $params;
};


// Routes
$router->route('admin_module_item_action', '/admin/<:module>/<:item>/<:action>')
    ->defaults(array('format' => 'html'))
    ->afterMatch($adminPrepend);

$router->route('admin_module_item', '/admin/<:module>/<#item>')
    ->defaults(array('action' => 'view', 'format' => 'html'))
    ->get(array('action' => 'view'))
    ->put(array('action' => 'put'))
    ->delete(array('action' => 'delete'))
    ->afterMatch($adminPrepend);

$router->route('admin_module_action', '/admin/<:module>/<:action>')
    ->defaults(array('format' => 'html'))
    ->post(array('action' => 'post'))
    ->afterMatch($adminPrepend);

$router->route('admin_module', '/admin/(<:module>)')
    ->defaults(array('module' => 'home', 'action' => 'index', 'format' => 'html'))
    ->post(array('action' => 'post'))
    ->afterMatch($adminPrepend);

Cheers,

--
Vance Lucas


On Tuesday, May 8, 2012 9:02:32 AM UTC-5, A387 wrote:

Vance Lucas

unread,
May 8, 2012, 11:22:35 AM5/8/12
to allo...@googlegroups.com
Looks like I've been writing too much JavaScript lately. The admin callback should be this:

// 'afterMatch' callback to prepend 'admin_' to module name
// @return array of $params
$adminPrepend = function($params, $method, $uri) {
    // Prepend 'admin_' to specified 'module' param from route
    $params['module'] = 'admin_' . $params['module']; // used "+" for concatenation the first time... sorry :(
    return $params;
};



On Tuesday, May 8, 2012 9:02:32 AM UTC-5, A387 wrote:

Adri Kodde

unread,
May 8, 2012, 11:33:20 AM5/8/12
to allo...@googlegroups.com
Yay, that's works perfectly! Thanks so much! :)

8 mei 2012 17:22
Looks like I've been writing too much JavaScript lately. The admin callback should be this:

// 'afterMatch' callback to prepend 'admin_' to module name
// @return array of $params
$adminPrepend = function($params, $method, $uri) {
    // Prepend 'admin_' to specified 'module' param from route
    $params['module'] = 'admin_' . $params['module']; // used "+" for concatenation the first time... sorry :(
    return $params;
};



On Tuesday, May 8, 2012 9:02:32 AM UTC-5, A387 wrote:
8 mei 2012 16:02
Reply all
Reply to author
Forward
0 new messages