Solved

codeigniter routing issues?

Posted on 2012-03-23
4
513 Views
Last Modified: 2012-03-23
Hi

Just starting out with codeigniter and have a couple of problems...

I have a simple controller, called public_site.php

in the routes.php I have set the default_controller to public_site

the controller has 2 methods

index

about

1: if I browse to ‘www.myurl.com/ci’ the index page displays fine

2: if I browse to ‘www.myurl.com/ci/index.php/about’ i get a 404 page not found

3: however if i browse to ‘www.myurl.com/ci/index.php/public_site/about’ it displays the page


also I am having problems with the location of the css.. in scenario 1 above the page displays with css correct, however with scenario 3, the page displays with no css… how do you keep track of the css location if you are using a template header and footer?

Thanks

cycledude
0
Comment
Question by:cycledude
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:frisoft
ID: 37756163
Your first example is basically the call of www.myurl.com/ci/index.php/public_site/index
if You want the ‘www.myurl.com/ci/index.php/about  url to work too, you should define route, for example in \application\config\routes.php add a line:
$route['about'] = 'public_site/about'

For css, js and other assets (and in fact for any url) i recommend use of the full path, see helper site_url() for the base url of your site.
0
 

Author Comment

by:cycledude
ID: 37756349
@frisoft

thanks for the help, adding the about route sorted it...

I am a little confused as I thought that was what the 'default_controller' was for...

so that anything in the url after index.php would be a method in the default_controller?

maybe I got the wrong impression?
0
 
LVL 1

Accepted Solution

by:
frisoft earned 500 total points
ID: 37756420
No, it's not as sophisticated, however it can be done, of course, you just need to overwrite the 404 error handler.
It work's like this:
 - if there is no segment after index.php, then it loads the index action of the default controller
 - if there is only one segment, then codeigniter treats it, as a controller and tries to load the index action of this "controller"
 - if there are 2 or more segments, then the first is the controller, second is the action and the others are passed as paramters to this action

Of course this is the basic behaviour, it can be modified by routes or by some kind of modular extensions, etc...
0
 

Author Closing Comment

by:cycledude
ID: 37756518
Thanks for the help, it was much appreciated.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question