0

i have to a controller with name about.php in controller folder. now in view folder i have a view with name about.php. in index.php view i want to call that view with the link but it is not calling i am very new to Codeignitor.

This is my calling code in index.php

<a href="<?php echo base_url();?>About/about">About Us</a>

This is my controller code about.php in controller folder.

class About extends CI_Controller {

    function index(){

        $this->load->view('about');
    }

}
tereško
  • 58,060
  • 25
  • 98
  • 150
Nasir
  • 421
  • 7
  • 21

2 Answers2

1

Your view should be called about.php and be in the views folder.

Your controller is then calling this view (correctly) called about.

Therefore a correct link to this view would be the following:

<a href="<?= site_url('about'); ?>">About Us</a>

You can read about the differences between base_url and site_url here.

Community
  • 1
  • 1
Tom
  • 1,068
  • 2
  • 25
  • 39
  • thank yor sir it is working fine but my link is like this "http://localhost/CodeIgniter/index.php/about" can we remove .php or index.php from this link – Nasir Mar 27 '14 at 17:40
  • Yes, you can do this with a simple change to your .htaccess file. This is in the CodeIgniter documentation: http://ellislab.com/codeigniter/user-guide/general/urls.html – Tom Mar 27 '14 at 17:41
  • sir what is index.php here can your explain – Nasir Mar 27 '14 at 17:42
  • index.php is the file index.php. When you go to index.php/about, you're really just going to index.php - the script then loads the controller 'about' and displays it. By adding a few lines to .htaccess you can make it appear that there is no index.php file, but essentially going to /about will still go to index.php. I would advise reading the CodeIgniter documentation for more information – Tom Mar 27 '14 at 17:45
0

Try with this:

<a href="<?php echo base_url();?>index.php/about">About Us</a>
kpmDev
  • 1,330
  • 1
  • 10
  • 28