CodeIgniter Forums
Problem with Links. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Problem with Links. (/thread-23215.html)



Problem with Links. - El Forum - 10-03-2009

[eluser]emcgfx[/eluser]
My link keeps repeating it self some times when I click on it. What I mean is it should be http://localhost/ci/site/blog but when I click on the link it always just repeats it by adding one more /blog, so if I would click five times it would make this link > http://localhost/ci/site/blog/blog/blog/blog/blog/ Instead it should of just go to my "blog" controller. But this not happens every time, only some times. I can't seem to figure out what is the problem. The only thing I could think of is that I've added pagination to my script and this is what happens now.


Problem with Links. - El Forum - 10-03-2009

[eluser]emcgfx[/eluser]
...


Problem with Links. - El Forum - 10-04-2009

[eluser]rampelli[/eluser]
i think you are new to CI ..
You should use anchor() function for links or you should provide the full path of the link using base_url()
function which is an CI function


Problem with Links. - El Forum - 10-04-2009

[eluser]emcgfx[/eluser]
Thanks rampelli, I've actually tried base_url() after I posted this and it worked just fine Wink No more errors so far.


Problem with Links. - El Forum - 10-05-2009

[eluser]davidbehler[/eluser]
base_url only works if you are not using index.php.
Try using site_url() instead, it provides the same as base_url but includes the index.php if it's needed and it even accepts arguments:

Code:
// base_url:
echo base_url(); // http://localhost/your_ci_folder/

// site_url without index file in config.php:
echo site_url(); // http://localhost/your_ci_folder/

// site_url with index file in config.php:
echo site_url(); // http://localhost/your_ci_folder/index.php/

// site_url with index file in config.php and arguments:
echo site_url('blog/view'); // http://localhost/your_ci_folder/index.php/blog/view

I usually use anchor() or site_url() to generate links/urls that point to my controllers/functions and base_url() when generating urls to images, js files and so that are not in the application folder, e.g.
Code:
<img src="&lt;?php echo base_url().'images/test/test.png'; ?&gt;" />



Problem with Links. - El Forum - 10-14-2009

[eluser]khagendra[/eluser]
Try like one of these

1. site_url('controlloerName') if u want to invoke the default function index().


2. site_url('controlloerName/functionName') if u want to invoke the some function


3. site_url('controlloerName/functionName/parameter1') if u want to invoke the some function with one parameter


4. site_url('controlloerName/functionName/parameter1/parameter2') if u want to invoke the some function with two parameters


----similarly for any no of parameters

Hope this will help u.