Welcome Guest, Not a member yet? Register   Sign In
Routing issue from welcome message
#1

[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') ?>
So, from this header file located in “views/inc“ I want to call a controller named posts located in the controller directory. I thought the link should look like this:
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/";
Lastly when the welcome_message comes up in the browser the address bar has what I accept.
Code:
http://localhost/CodeIgniter/CIpagination/index.php
And when I click on the link to go to post I see this in the header and get the not found URL message.
Code:
http://localhost/posts/
PS I read the routing section in the user guide.
#2

[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.
#3

[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.
#4

[eluser]rogierb[/eluser]
If you install CI in some other place the the root, make sure you use
Code:
<a href="&lt;?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.
#5

[eluser]William Rouse[/eluser]
rogierb:
Your suggestion of ‘<a href="&lt;?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!
#6

[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>
#7

[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="&lt;?php print site_url('posts') ?&gt;">Posts</a></li>

I suggest you stop everything you are doing and get some fundamentals under your belt, starting with relative vs. absolute paths.
#8

[eluser]wiredesignz[/eluser]
Isn't it funny how a seemingly simple topic can get more confusing as it goes along. Tongue
#9

[eluser]William Rouse[/eluser]
Thanks and I started reading.




Theme © iAndrew 2016 - Forum software by © MyBB