Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Problem with folder having same name as view argument
#1

[eluser]yannyannyann[/eluser]
Hi,

I have a public folder on root my app, called "public".

My system is working very well with my current pages.
I have a routing system like this :


Code:
http://www.mysite.com/about-me <= http://www.mysite.com/pages/index/about-me


I have now to create a page called "publications".

But when I try to access it I have an error 404 :
Code:
http://www.mysite.com/publications

Somehow in Codeigniter there must be a rule that redirects the urls depending if what the user typed is similar to an existing folder ?

How can I do to say to my app that when typing "publications" I don't mean "public" ?


thanks !
#2

[eluser]Cro_Crx[/eluser]
I'm assuming your doing the routing via the routes.php file in the config folder?

If so you'll just need to create another route after the one for your public redirection. So something like
Code:
$route['questions'] = "questions";

If your redirecting using mod_rewrite, i'm really lost! lol
#3

[eluser]yannyannyann[/eluser]
hmmm doesn't work.

This is my routing config for the moment :

Code:
$exclude = array(
                '.',
                '..',
                'index.html',
                'pages.php'
    );
    
$handle = opendir(APPPATH.'controllers/');

while( false !== ($file = readdir($handle)))
{
    if( !in_array($file, $exclude))
    {
        if ( !is_dir(APPPATH.'controllers/'.$file) )
        {
            $file = substr($file, 0, strlen($file) - 4);                
        }
        $installed_modules[] = $file;
    }
}
closedir( $handle );
                                

foreach ($installed_modules as $module) {

    // e.g. controler/
    $route[$module] = $module;
    
    // e.g. controler/view/param
    $route[$module.'/(.*)'] = $module.'/$1';
        
}

$route['(.*)'] = "pages/index/$1";
#4

[eluser]Cro_Crx[/eluser]
whoa, that's a bit nutz...


you don't really need to do all that, you could just have one line to achieve pretty much the same thing, something like this:

Code:
$route['pages:(any)'] = "pages/index/$1";


because doing this

Code:
$route[$module] = $module;

means your mapping the controllers route to itself and the same for the statement below!

Code:
$route[$module.'/(.*)'] = $module.'/$1';


I hope that sorta helps, I'm not 100% sure if that's what your trying to achieve.
#5

[eluser]yannyannyann[/eluser]
Hi everybody,

If this can be helpful to somebody:

I followed the codeigniter video tutorial to build up a CMS from Haughin (google it, you will find it).

I ended up with that code in routes.php:

Code:
$exclude = array(
                '.',
                '..',
                'index.html',
                'pages.php'
    );
    
$handle = opendir(APPPATH.'controllers/');

while( false !== ($file = readdir($handle)))
{
    if( !in_array($file, $exclude))
    {
        if ( !is_dir(APPPATH.'controllers/'.$file) )
        {
            $file = substr($file, 0, strlen($file) - 4);                
        }
        $installed_modules[] = $file;
    }
}

closedir( $handle );
                                

foreach ($installed_modules as $module) {

    // e.g. controler/
    $route[$module] = $module;
    
    // e.g. controler/view/param
    $route[$module.'/(.*)'] = $module.'/$1';
        
}

$route['(.*)'] = "pages/index/$1";


So with this, if you have a folder called "public" and if you want to have a page called "publicsomething" like "publication", the default set up will not allow it.

You will need to edit your htaccess file, by adding a SLASH after the public folder :
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|public\/|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L]




Theme © iAndrew 2016 - Forum software by © MyBB