Page title not working in codeigniter?

Below title does not appear in the title of the web page. It shows the default value.

code:

public function index()
{
    $data['page_title'] = "Welcome to codigniter";
            ...................
            ...................

}

      

+3


source to share


4 answers


just pass the variable $data

when loading the view and then echo in $page_title

between <title></title>

in your view.



<title><?php echo $page_title; ?></title>

      

+1


source


Try it like this:

public function index()
{
   $data['page_title'] = "Welcome to codigniter";
        ...................
        ...................
   $this->load->view('page',$data);
}  

      



VIEW:

<title><?php echo $page_title; ?> </title>

      

0


source


You need to add below code in your controller:

$this->data['title'] = 'test';
$this->load->view('folder/viewname',$this->data);

      

or you can use

 $data['page_title'] = "Welcome to codigniter";

      

And access the $ title in your view file. Please, check him.

mark it accepted if it works

0


source


Yes, it will work on the code. But only in this function.

Every time you create a controller, just create some kind of global variable so you can use it everywhere. See this code:

class Code extends CI_Controller {
 var $TITLE = 'Welcome to codeigniter';
 function Code(){
    parent::__construct();
 }
 function index(){
   $this->load->view('page');
 }
}

      

And when you call this controller, you can use this variable anywhere in the controller, model, or view that is connected to that controller. Like this:

echo $this->TITLE; 

      

0


source







All Articles