Welcome Guest, Not a member yet? Register   Sign In
Set different page title for every other page.
#1

[eluser]zombica[/eluser]
Hey Guys is there any support in CI that we can set different page title for each view page.
I have looked for this in threads and all they say, their is some support in helper classes but i couldn't find any thing over their.

Regards
#2

[eluser]Thorpe Obazee[/eluser]
Errmm... of course there's a way to set different page title for each view page. What exactly is preventing you from doing it?
#3

[eluser]zombica[/eluser]
Nothing preventing me, but for what i m looking for is not the right answer i m getting for it. I need to change my page title for every view page by specific controller class.
Is their any possibility for this.

Regards,
Thanks......
#4

[eluser]Thorpe Obazee[/eluser]
You can always set the value in your Controller constructor.

Code:
function Courses()
    {
        parent::MY_Controller();
        $this->data['title'] = 'insert_title_here';
    }

Code:
// View
<title><?php echo $title;?></title>
#5

[eluser]huzzi[/eluser]
This is how I do it.

Extend the default controller as shown, this file goes inside the libraries folder.

MY_Controller.php
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends Controller {
    protected $data = array();
    
    protected function __construct() {
        parent::__construct();
        $this->load_defaults();
    }
    
    protected function load_defaults() {
       $this->data['pageTitle'] = 'Page Title';
    }
}
?>

Now in the controller set the page title.
Code:
<?php
class Form extends MY_Controller {

function __construct() {
        parent::__construct();
    }
    
    function index()
    {
        $this->data['pageTitle'] = 'Your page title';
            $this->load->view('homepage');
    }
}
?>
View
Code:
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $pageTitle; ?></title>
</head>
<body>
<?php echo $content; ?>
</body>
</html>

Hope this helps.
#6

[eluser]zombica[/eluser]
Thanx guys for the help. actually may be i am unable to explain my problem i have a common header file which i am including on my each view page now say if i have a controller class "Users" under which i have created multiple view pages for CRUD operation how i can differentiate them regarding title page.


The technique you both told me i have applied it is throwing following error. some kind of HTML is displayed on the title bar like this"<div style=borderConfusedolid 1px #99000;padding:5px"><H4>A PHP error....



Regards,
Thanx............
#7

[eluser]Thorpe Obazee[/eluser]
Code:
function Courses()
    {
        parent::MY_Controller();
        $this->data['title'] = 'insert_title_here';
    }

    function yourmethod()
    {
        $this->load->vars($this->data);
        $this->load->view('viewfile');
    }

Code:
// View
&lt;title&gt;&lt;?php echo $title;?&gt;&lt;/title&gt;

use $this->load->vars(); so that it's set in all views.
#8

[eluser]zombica[/eluser]
Thanx Buddy it works. but still i am confused say if i load a view page for add user or update user or say view user from different function under same controller class although the "$this->load->vars($this->data);" call will be given separately to each function but in the controller class constructor the definition of $this->data['title']='title_goes_here' is defined only once and every time we will get same value on each view page.


Sorry for disturbing you all.

Regards,
Thanx
#9

[eluser]zombica[/eluser]
Thanx guys i find he solution i have defined the $this->data="title" w.r.t each CRUD function in it self.

Thanx a lot for cooperation.

Regards.
Zombica.




Theme © iAndrew 2016 - Forum software by © MyBB