Welcome Guest, Not a member yet? Register   Sign In
Route Confusion
#1

[eluser]Phunky[/eluser]
Please excuse me if i am being outright dumb but i just cant grasp how to setup the routes i wish.

Im very new to IC and have always struggled to get to grips with other forms of MCV Frameworks such as CakePHP and so.

I'm setting up a Controller that will handle all Static content pages in my application that do not tie in with anything.

Such as Welcome, about, contact etc...

Im struggling to setup the route correctly as i wish to have the pages on the base of the domain like www.site.com/about/ or www.site.com/welcome/

How do i go about this without setting up each one manually??
#2

[eluser]Glen Swinfield[/eluser]
You can't. You must have at least 1 uri segment that relates to a controller - then some way of telling the controller which page to display.

So if you have a Controller - 'Pages' you would need a method 'Content()' - this method looks at the url and decides which page to display:

Code:
function Content(){
   $page = $this->uri->segment(2);

   if($page == 'about'){
      $this->load->view('about');
   }

   // Or something (you could use a switch statement)
}

Then your url will be http://www.site.com/content/about

Your route would be:
Code:
$route['content:any'] = "pages/content";

The only way to achieve what you have asked for is to create a Controller for each static page and have the index() method deliver the content for each. - This is not a good idea.

Update: People seem to ask for this a lot - what's the obsession with single level urls? - they're really no clearer to the user if they use descriptive words.
#3

[eluser]Phunky[/eluser]
Oh thats annoying Sad

It would be a total waste to create a controller for each static page, i guess i could just create a .htaccess URL rewrite instead.
#4

[eluser]Eric Barnes[/eluser]
I think I seen this done with Elliot's demo. I believe this is the link:
http://www.filepanda.com/get/nxx2otjn/

Basically what he did was something like this to the routes file:
Code:
$exclude =     array(
                    '.',
                    '..',
                    'index.html',
                    'main.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;
        }
    }
    
    // print_r($installed_modules);
    
    closedir($handle);
    
                        
foreach ($installed_modules as $module)
{
    // e.g. index.php/news
    
    $route[$module] = $module;
    
    // e.g. index.php/news/view/hello-me/
    
    $route[$module."/(.*)"] = $module."/$1";
    
}

$route['(.*)'] = "main/page/$1";
#5

[eluser]Phunky[/eluser]
That works a treat Smile

Thanks!
#6

[eluser]Phunky[/eluser]
[quote author="Codepat" date="1184266245"]People seem to ask for this a lot - what's the obsession with single level urls? - they're really no clearer to the user if they use descriptive words.[/quote]

People like short URLs simple as Smile Plus im porting over my own CMS system to IC and have to keep the structure of a current site intact.
#7

[eluser]esra[/eluser]
Have you considered adding something like a is_static column to your content table along with a uri column. Then design your content controller to load static or dynamic content based on the is_static value.




Theme © iAndrew 2016 - Forum software by © MyBB