CodeIgniter Forums
Strange URL behaviour - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Strange URL behaviour (/showthread.php?tid=18454)



Strange URL behaviour - El Forum - 05-06-2009

[eluser]philstan[/eluser]
I am developping a project for a client in CI for the first time and I love it. However, I am having a problem with some very strange and inconsistent behavior in the URLs of one page.

My view page has this simple line of code:

<a href="&lt;?base_url();?&gt;opportunities/newpost">&lt;?php echo img('assets/images/new_post_button.gif');?&gt;</a>

Which points to this function in the Controller:

function newpost()
{
$data['title'] = "Upcoming Volunteer Opportunities New Posts";
$data['header'] = "Company Name";

$main_data['h1_title'] = "Upcoming Volunteer Opportunities - New Post";

$data['main'] = $this->load->view('opportunities/newpost_view',$main_data, TRUE);

$this->load->view('template', $data);

}

This SOMETIMES results in this:

http://.../opportunities/opportunities/opportunities/opportunities/opportunities/newpost

depending on how many time the new_post_button.gif is clicked.

As I said, this occurs sometimes and seems to have something to do with a forward slash after "opportunities". In other words this:

/opportunities/ (with forward slash) seems to cause the problem but /opportunities (without forward slash)

Thank you for your help


Strange URL behaviour - El Forum - 05-07-2009

[eluser]TheFuzzy0ne[/eluser]
The URL for your button is probably relative, and not absolute. Try suffixing a forward slash. So "opportunities/newpost" would become "/opportunities/newpost". Also, you could load the URL helper and use site_url to generate the URL (please see the [url="http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html"]user guide documentation on the URL helper[/url]).


Strange URL behaviour - El Forum - 05-07-2009

[eluser]philstan[/eluser]
Thank you.

I used the URL helper and anchor() format. I has cured the problem.