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
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.

Link to comment
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.

 

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.