Routing issue from welcome message |
[eluser]William Rouse[/eluser]
And today’s problem is… “My application can’t find a controller.” I modified the welcome view so it now has a menu with a series of links. I am running in netbeans and I can launch the application and the welcome view comes up modified. The welcome page, “welcome_message” calls a header file where the links are like this. Code: <?php $this->load->view('inc/header') ?> Code: <a href="/posts/">Posts</a> or <a href="posts/">Posts</a> The only significant routing change I made was in the config.php: Code: $config['base_url'] = "http://localhost/CodeIgniter/CIpagination/"; Code: http://localhost/CodeIgniter/CIpagination/index.php Code: http://localhost/posts/
[eluser]Colin Williams[/eluser]
You need to route to an internal path. This will not include your basepath or base URL. Tell us where CI is installed. It's hard to tell from what you've provided. And tell use the name of the controller you would like to be your default controller.
[eluser]William Rouse[/eluser]
The CI installation for this project is "CIpagination". The default controller is the Welcome controller. The Template library is over kill. The solution must be much simpler than that.
[eluser]rogierb[/eluser]
If you install CI in some other place the the root, make sure you use Code: <a href="<?php echo site_url(">Posts</a> Otherwise you get routed to the root of your apache installation, hence the http://localhost/posts/ Also, you need to put a .htaccess in your webfolder to be remove the index.php part.
[eluser]William Rouse[/eluser]
rogierb: Your suggestion of ‘<a href="<?php echo site_url(">Posts</a>’ does not seem like a complete statement and I am not sure what you mean. Could you give it another try for me? The root for this project is “CIpagination”. Are you suggesting that I use a .htaccess file with the contents from the user guide? RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L] Thanks!
[eluser]William Rouse[/eluser]
I just got back to working on this problem. I realized in my initial note I overstated the problem. Why, or how do you call a controller from a view? I am so surprised that this does not work Code: <li><a href="posts/">Posts</a></li>
[eluser]Colin Williams[/eluser]
It's because you are using a relative link. You should use the URL helper and the site_url() function. Code: <li><a href="<?php print site_url('posts') ?>">Posts</a></li> I suggest you stop everything you are doing and get some fundamentals under your belt, starting with relative vs. absolute paths.
[eluser]wiredesignz[/eluser]
Isn't it funny how a seemingly simple topic can get more confusing as it goes along. ![]()
|
Welcome Guest, Not a member yet? Register Sign In |