Welcome Guest, Not a member yet? Register   Sign In
Problem with Links.

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.


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

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

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:

// 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.
<img src="&lt;?php echo base_url().'images/test/test.png'; ?&gt;" />

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.

Theme © iAndrew 2016 - Forum software by © MyBB