Welcome Guest, Not a member yet? Register   Sign In
Custom Pages (CMS style)
#1

[eluser]tdktank59[/eluser]
So I had the need to be able to create pages that did not require a controller to be present.
In this case it was for the CMS.

The basic principal was you would have the a page like this:
www.url.com/page_name

I have found a pretty nice work around for it.

The way I built it was to all the system to catch what ever it could first and if it could not find a valid path, then it would send it off the the default controller defined in the routes.php file. That way the user could not override any default functionality that the site has.

Heres the code
Code:
// Since the sytem could not find it, lets redirect it to the CMS to handle
// At some point we should load of the database before this point so we can verify this is real before
// we send it off, but this is a temporary work around until then.

$newSegments[0] = $this->default_controller;
$newSegments[1] = 'index';

foreach ($segments as $val)
{
    $newSegments[] = $val;
}

$segments = array();
$segments = $newSegments;
return $segments;

Place it at the end of the _validate_request function in Router.php before the show_404 line.
And then make sure you set your default_controller to a controller that will catch the uri and search your database for the page.

Enjoy.

I plan to figure out how to load the DB early in the system so I can check it while still in the router before sending it off to the default_controller. But this works for now.
#2

[eluser]codeninja[/eluser]
Why not have a simple CMS controller and set that as a default controller that http://xyz.com get's routed to.. and then create a __remap() function to handle everything.. ???
#3

[eluser]tdktank59[/eluser]
Problem is the routes.php checks to see if a file exists, so unless you intercept it there it will 404 on you.

Also im not too concerned about my system folder since I am creating a CMS/Framework out of this. Basically fixing it up to do what I want it to do. Im prettu sure you could extend the routes in the application folder and extend the function. I just don't care as much




Theme © iAndrew 2016 - Forum software by © MyBB