0

I am trying to link my view page to another controller.

my test_view.php page

//this page address is base_url/controller1/function1
<a href='controller1/function2'> test </a>

If i click, the page address will be base_url/controller1/function1/controller1/function2 which is not my desire.

my controller

   //the first function1 is to show my test_view page
    function function1 (){
       $this->load->view('test_view');
    }

   //I can't get to this function2 with the link I used
    function function2 (){
      $this->load->view('funny');
    }

Anyone could help me about this? Thanks a lot.

0

3 Answers 3

2

Sure--you just need to tell CodeIgniter to display the path:

<a href="<?php echo site_url("controller1/function2");?>">

One thing: This displays the absolute path of your site as defined in your config, not the relative path.

I prefer relative paths, so I like to create a universal function called site_path to do the same thing without the absolute URL. I include it in one of my universally loaded libraries and it looks something like this:

function site_path($url) {
    return "/$url";
}

The benefit of this is that, if I initially develop the site in a subdirectory, I can set site_path to return "/subdirectory/$url" and then just remove the subdirectory once I launch.

Sign up to request clarification or add additional context in comments.

Comments

2

It's linking to a relative URL, you need to start with a '/' to use the web root

<a href='/controller1/function2'> test </a>

Comments

2

you can use following code in test_view.php page,
<a href='<?php echo base_url();?>controller1/function2'> test </a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.