CodeIgniter Forums
Set Page Title on each controller::method - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Set Page Title on each controller::method (/showthread.php?tid=20613)



Set Page Title on each controller::method - El Forum - 07-15-2009

[eluser]OliverHR[/eluser]
I set page dinamically in this way.

On MY_Controller class:
Code:
class MY_Controller extends Controller
{
  var $title;
  function __construct()
  {
    parent::Controller();

    $this->title = $this->uri->segment(1) . (($this->uri->segment(2))? ' - '.$this->uri->segment(2) : '');
  }
}

On the Controller:
Code:
class Acontroller extends MY_Controller
{
  var $title;

  function __construct()
  {
    parent::__construct();
  }

  function amethod($avar)
  {
    $this->load->view('aview');
  }
}

On the View
Code:
<html>
  <header>
    <title><?=$this->title ?></title>
  </header>
<body>
Content here...
</body>
</html>


You can use in conjuntion with(i get the idea from this excellent article).

Michael Wales : CodeIgniter Convention over Configuration

Hope this help. :-)