/    Sign up×
Community /Pin to ProfileBookmark

writing an effective router/dispatcher for mvc pattern ??

hello forums !!
I am trying to make an router/dispatcher for oo mvc pattern.
I would like to have one default router pattern ie controller/method/id and other is customized one
for example

[code=php]http://yoursite.com/controller/method/id/params => $controller->method($id[, $params])(general)
http://yoursite.com/admin/controller/method/id/params => $controller->admin_method($id[, $params]) (customized)[/code]

Can anybody provide good suggestions/samples in dispatching such method.
Note: dispatching method should work both for url rewriting turned on or off by changing some flags.

Thanks in advance for your valueable suggestions.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@PHPychoauthorJan 25.2008 — Knock Knock... Can anybody come with better ideas
Copy linkTweet thisAlerts:
@TheRaveJan 25.2008 — People with adequet knowledge are not online 24/7, they cannot always respond within 24 hours.

Also, if no one has responded it normally means no one understands what you want or no one has the knowledge on how to achieve what you want.

Sorry.
Copy linkTweet thisAlerts:
@ScleppelJan 26.2008 — Possibly (not tested)
[code=php]<?php

// Create an array from the REQUEST_URI parts.
$uri_parts = explode('/', trim(current(explode('?', getenv('REQUEST_URI'))), '/'));
$uri_parts_count = count($uri_parts);
if(($uri_parts[0] == 'admin' && $uri_parts_count >= 3) || $uri_parts_count >= 2)
{
if($uri_parts[0] == 'admin')
{
$admin = 1;
$uri_parts[2] = 'admin_' . $uri_parts[2];
}
else
{
$admin = 0;
}
// Get any method parameters (starting at 2 (or 3) because 0 (or 1)
// is the controller name and 1 (or 2) is the method name).
$params = array();
for($i = $admin + 2, $i < $uri_parts_count, $i++)
{
$params[] = $uri_parts[$i];
}
unset($uri_parts_count);
// Run it.
call_user_func_array(array($uri_parts[$admin], $uri_parts[$admin + 1]), $params);
}
else
{
// Missing controller and/or method.
}[/code]


Edit: added the admin part.
×

Success!

Help @PHPycho spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...