title: Pass Variable from View to Controller in Codeigniter using PHP
body: <p>I am working on a project where I need to pass a variable from the View to a Controller's method where I'll be using that variable's value. I have tried the following.</p>
  
  <p><strong>View</strong></p>
  
  <pre><code>...
  $user = 3;
  ...
  &lt;ul class="nav navbar-nav navbar-right"&gt;
                  &lt;li&gt;
                      &lt;a href="&lt;?php echo base_url() ?&gt;index.php/studentDashboardController/index?user=$user"&gt;
                          My Dashboard
                      &lt;/a&gt;
                  &lt;/li&gt;
  ...
  </code></pre>
  
  <p><strong>studentDashboardController (<em>Method 1</em>)</strong></p>
  
  <pre><code>public function index()
  {
      ...
      if ( isset($_GET['user']) ) {
          $user = $_GET['user'];
          echo '&lt;script type="text/javascript"&gt;alert("User taken from GET: ' . $user . '")&lt;/script&gt;';
      }
      ...
  </code></pre>
  
  <p><strong>Output for Method 1</strong></p>
  
  <p><a href="https://i.stack.imgur.com/kld0E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kld0E.png" alt="Output for Method 1"></a></p>
  
  <p><strong>studentDashboardController (<em>Method 2</em>)</strong></p>
  
  <pre><code>public function index()
  {
      ...
      if($this-&gt;input-&gt;get())
      {
          $user = $this-&gt;input-&gt;get('user');
          echo '&lt;script type="text/javascript"&gt;alert("Uid taken from Method 2 ' . $user . '")&lt;/script&gt;';
      }
      ...
  </code></pre>
  
  <p><strong>Output for Method 2</strong></p>
  
  <p><a href="https://i.stack.imgur.com/ZbOdy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZbOdy.png" alt="Output for Method 2"></a></p>
  
  <p>Any suggestions on how to get the value of this passed variable will be highly appreciated. </p>