Solved

codeigniter routing issues?

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now