Solved

codeigniter routing issues?

Posted on 2012-03-23
4
512 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

808 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