Welcome Guest, Not a member yet? Register   Sign In
Best way to this url rewriting and loading other controllers?
#1

[eluser]inet411[/eluser]
I'm experimenting with codeigniter.

I like to have search engine friendly urls like this:
example.com/honda/accord or
example.com/honda

where honda is the category and accord is the page.
I can do this easily with procedural programming like so:

.htaccess
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

index.php
Code:
// I put some code here to explode the url and get it into segments.....
// so $category = honda and $page = accord
if(isset($page)) {
    include('page.php');
} elseif(isset($category)) {
    include('category.php');
}

based on the two urls above the first one would include page.php the second would include category.php
then the category.php page does whatever a category page does and the page.php page does whatever a page page does.

But with codeigniter I have the same .htaccess file and here is my index.php (welcome.php)

welcome.php
Code:
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        if(segment(1) && segment(2)) {
            //how do I include the category.php controller?
        } elseif(segment(1)) {
            //how do I include the page.php controller?
        }
    }
}


I understand I can use urls like:
example.com/category/honda/page/accord
example.com/category/honda
And that will do exactly what I want ...
But I don't want the words category or page in the url. I want the urls that I showed above.

Any suggestions?
What about creating a new method so I can $this->load->controller('category.php'); // is that possible? or would that have side effects?


Messages In This Thread
Best way to this url rewriting and loading other controllers? - by El Forum - 01-07-2010, 09:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB