Jump to content

subdirectory controller - how?


Strike X

Recommended Posts

I have developed basic MVC framework..

 

The routing does this at the moment:  whatever.com/classname/action/value

 

I wanted to create admin backend, I will need a subdirectory with new controller?

 

url will need to look something like this: whatever.com/admin//classname/action/value

 

Do you have any example of code how does subdirectory controller/routing work?

Link to comment
https://forums.phpfreaks.com/topic/197349-subdirectory-controller-how/
Share on other sites

You would simply need to configure a base uri somewhere. If this then has a value of /admin, ignore admin within the uri.

 

Of course, for what your actually doing it sounds like you need to also implement what some frameworks term modules[/m]. So the urls then become whatever.com/modulename//classname/action/value. This way you don't need to setup a new application within /admin, just make it a module of your main application.

You would simply need to configure a base uri somewhere. If this then has a value of /admin, ignore admin within the uri.

 

Of course, for what your actually doing it sounds like you need to also implement what some frameworks term modules[/m]. So the urls then become whatever.com/modulename//classname/action/value. This way you don't need to setup a new application within /admin, just make it a module of your main application.

 

I don't know modules mean for the MVC framework but I managed to get it working if controller file found in the sub directory.

 

Here is example of code:

 

$args = explode('/', $route);
            if (is_dir($this->pathfolder . $args[0]))
            {
               $this->pathfolder =  $this->pathfolder . $args[0];
               array_shift($args);
            }
            
            if (count($args) > 0)
            {
                if (file_exists($this->pathfolder . '/' . $args[0] . '.php'))
                {
                    $this->controller = $args[0];
                }
                else {
                    // do something if not found.
                }
            }

 

Is that ok?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.