I am writing an application in CodeIgniter where I specify the <title>
meta-tag on every page in every controller which I have managed to send to my header template. However, now I have created an application that fetch credit cards and their titles from the database, through an CodeIgniter model. I would like to automatically fetch and use the credit card's name in <title>
so that i don't need to change it manually, but I'm a little stuck on how to proceed.
This is my code as of now:
Controller
public function show($card = NULL)
{
$data['query'] = $this->Listing_model->get_card($card);
$header["page_title"] = from the model
$this->load->view('includes/header',$header);
$this->load->view('listings/listing_card',$data);
$this->load->view('includes/footer');
}
Model
function get_card($card = FALSE)
{
$query = $this->db->get_where('creditcards', array('slug' => $card), 0,1);
return $query->result();
}
I have been following the official CodeIgniter documentation when creating this application, but so far no luck. Any solutions?
Controller
View
Try this
In Model
In Controller
In View
Controller
View
In your listing card view, do this:
replace 'title' with the name of the column on your database that keeps the title of the credit card...so you are passing the results of the query you ran in your controller to this view, and then using a foreach loop to display data of the specific credit card
You can use template library for robustness and use as follows:
Controller
Views
Reference: https://github.com/philsturgeon/codeigniter-template
Just to add another, there's no reason this shouldn't work:
In your view:
If this doesn't work your query isn't returning what you think it is.