suii
suii

Reputation: 392

passing value from view to controller without using <form> codeigniter

can someone give me some tips on how can i pass a value from a view to a function in a controller without using a form? i just use only thanks here is my code.

view:

     <ul>
     <li><a href="<?php echo base_url(); ?>main/passby">Add subject</a></li>
      </ul>
      <ul class="nav nav-sidebar">
        <li><a href="<?php echo base_url(); ?>main/logout">Logout</a></li>
      </ul>

controller:

  public function passby($page){

        $uri = 'admin/'.$page;
        $this->load->view('header');
        $this->load->view('admin/navigation');
        $this->load->view('admin/sidebar');
        $this->load->view($uri);
        $this->load->view('footer');
  }

i want to put a value on the anchor tag and pass it to the controller as a parameter page so that my page will load the view without using may functions.

Upvotes: 1

Views: 3708

Answers (1)

Kevin
Kevin

Reputation: 41885

You can pass, (for example a string) on the URI segment. Example:

<li><a href="<?php echo base_url(); ?>main/passby/1">Add subject</a></li>
                                              //  ^ 1 just for example

Or concatenate a variable:

<?php $id = 123; ?>
<li><a href="<?php echo base_url() . 'main/passby/' . $id; ?>">Add subject</a></li> 

Then you can use it on the function.

public function passby($page)
{
    // $page = 1;
}

Upvotes: 3

Related Questions