Solved

codeigniter routing issues?

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

724 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