Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-24-2008, 09:51 AM   PM User | #1
PHPycho
Regular Coder

 
Join Date: Dec 2005
Posts: 217
Thanks: 1
Thanked 0 Times in 0 Posts
PHPycho has a little shameless behaviour in the past
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
PHP Code:
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) 
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.
PHPycho is offline   Reply With Quote
Old 01-25-2008, 11:19 AM   PM User | #2
PHPycho
Regular Coder

 
Join Date: Dec 2005
Posts: 217
Thanks: 1
Thanked 0 Times in 0 Posts
PHPycho has a little shameless behaviour in the past
Knock Knock... Can anybody come with better ideas
PHPycho is offline   Reply With Quote
Old 01-25-2008, 02:53 PM   PM User | #3
the-dream
Regular Coder

 
the-dream's Avatar
 
Join Date: Mar 2007
Location: Northamptonshire, UK
Posts: 477
Thanks: 8
Thanked 4 Times in 4 Posts
the-dream can only hope to improve
I was creating a blogging system and created something like this. You will have to customise it but here it is:

PHP Code:
<?php

    
echo '<p>This is our index.php file!</p>';
    
    
// Requested URL
    
$url $_SERVER['REQUEST_URI'];
    
    
// Removes App Root from URL
    
$url str_replace('/BlogSite/'''$url);
    
    
    
$routes = array(
    
                    array(
'url' => '/^posts\/(?P<id>\d+)$/''controller' => 'posts''view' => 'show'),
                    array(
'url' => '/^posts\/(?P<id>\d+)\/edit$/''controller' => 'posts''view' => 'edit')
                    
                    );
    
        
$params = array();
        
        
$route_match false;
    
    foreach(
$routes as $urls => $route) {
    
        if(
preg_match($route['url'], $url$matches)) {
            
            
$params array_merge($params$matches);
                
              
$route_match true;
                
                break;
        
        }
    }
    
    if(!
$route_match) { exit('No Route Found!'); }
    
    include(
'controller/'.$route['controller'].'.php');

?>
I used a .htaccess file so all my /dirs/ get passed through the index.

Hope this helps.
__________________
Branchr Advertising Network
the-dream is offline   Reply With Quote
Old 01-25-2008, 09:05 PM   PM User | #4
the-dream
Regular Coder

 
the-dream's Avatar
 
Join Date: Mar 2007
Location: Northamptonshire, UK
Posts: 477
Thanks: 8
Thanked 4 Times in 4 Posts
the-dream can only hope to improve
Any Good?
__________________
Branchr Advertising Network
the-dream is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:06 AM.


Advertisement
Log in to turn off these ads.