title: How to get base url in pre_controller hook in codeigniter
body: <p>I am working on hook file, i am using <code>pre_controller</code> function of hook, but when i tried to use <code>base_url()</code> function in it, it is not working for me, it give me this error <code>Call to undefined function base_url()</code>, can anyone please help me to resolve this error ? here i have added my whole function</p>
  
  <pre><code>$hook['pre_controller'] = function()
  {
      $this-&gt;CI = get_instance();
      $ci =&amp; get_instance();
      $router =&amp; load_class('Router', 'core','uri','url');
      $controller_name = $router-&gt;fetch_class();  
      $action_name = $router-&gt;fetch_method();  
      $segement = $router-&gt;uri-&gt;segment(2);
      echo base_url(); die;
      try {   
          $rc = new ReflectionClass($controller_name);
      } catch (Exception $ex) {
          if($segement == "") {
              echo base_url(); die;
              //header("Location:".$controller_name.'/overview');
              //redirect($controller_name.'/overview');
              //exit;
          }
      }  
  };
  </code></pre>