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?
Create a base controller. The default location for this is
application/core/MY_Controller.php =>
this can be changed via the config. By using$this->site_data
you can add variables in your base class and use them in every controlle/viewAnd I think your get_where is wrong:
your limit is 0
access the data in your view
You can create a Base Controller and Extends all you other controller to that base controller.
Like this
Then In Your Controller
And in you views access the page title like this:
In your model - don't return
$query->result()
, just return$query
:Controller:
You may need to create some routes for your show function. Codeigniter URI Routing
I am not sure if you have set up a htaccess for your main directory so you could remove the
index.php
from your url.Try this code below
Model:
Controller:
Your_controller_name.php
View:
Controller :
view: and You just need to write in your header file like :
A simple example:
Controller
View