CodeIgniter Forums
Set page title from DB value - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Set page title from DB value (/showthread.php?tid=56961)



Set page title from DB value - El Forum - 02-03-2013

[eluser]razputin[/eluser]
I use $data['title'] to set the page title and I'm looking for a way to change the title based on the page content.
Is it possible to assign an element in a data array to another? Something like this (doesn't work):

Code:
$data['article']=$this->article_model->get_article($article_id);
$data['title']=$data['article']['title'];

Or is there a better approach to set the page title dynamically?


Set page title from DB value - El Forum - 02-03-2013

[eluser]Eduard Stankovic[/eluser]
what is your code of Article_model::get_article() ?

are you returning result_array() or row_array() ?


Set page title from DB value - El Forum - 02-03-2013

[eluser]razputin[/eluser]
It's row_array()

from model:

Code:
function get_article($article_id)
{

$query = $this->db->get_where('articles', array('id' => $article_id));
  return $query->row_array();
}



Set page title from DB value - El Forum - 02-03-2013

[eluser]CroNiX[/eluser]
Code:
$data['article']=$this->article_model->get_article($article_id);

in view
Code:
echo $article['title'];

no need to pass it 2x