Search code examples
phpmodel-view-controllerhref

base_url () function is not working ( Code ignitor)


im new to php and recently im trying to load my html and css file into the code ignitor . Thus, my website wont load when i try to link between pages using href, id be so grateful if anyone can point out my mistakes, thankyou

this one is the view part where i want to link between pages

 <header>
    <nav>
            <ul>
                <li> <a href="<?= base_url()?> signup">Sign ups</a></li>    
          </ul>
    </nav>
</header>   

this one is the signup controller

<?php

class signup extends extends CI_controller{

public function index()
{
    $this -> load -> view ('header');
    $this -> load -> view ('signup_view');
    $this -> load -> view ('footer');

}

}

Solution

  • This looks like CI 2.x - if it's CI 3+ you need to titlecase your controller like in my code below. However, your issue is not loading the url helper. You can place it in the construct of your controller or right in the index function

    <?php
    class Signup extends extends CI_controller{
    
    function __construct() {
      parent::__construct();
      $this->load->helper('url');
    }
    
    public function index() {
    // ...
    

    That will enable it in that controller, but you can enable it globally by placing this in your config/autoload.php file:

    $autoload['helpers'] = array('url');