(09-01-2015, 01:27 AM)davidgv88 Wrote: (08-31-2015, 09:56 PM)jjalvi Wrote: (08-31-2015, 01:28 AM)rtorralba Wrote: (08-31-2015, 12:14 AM)davidgv88 Wrote: Hi jjalvi.
For dynamically change the Page title of your product pages:
In your view you can send the title from your controller.
In controller:
Code:
$data = array();
$data['page_title] = 'The Page title';
$this->load->view('your_view',$data);
In your_view.php
Code:
<?php
if(empty($page_title)){
$page_title = 'Default Title';
}
<html>
.....
<title><?php echo $page_title; ?></title>
</html>
?>
I prefer in view to use a ternary operator, but is just a preference:
Code:
<title><?= empty($page_title) ? $page_title : 'Default Title' ?></title>
Thanks heaps rtorralba and [b]davidgv88 .[/b]
I managed to implement the code successfully.
Now I am just trying to figure out how to put the title of my product automatically as the title of my page. For emaple if you follow this page http://www.webuyback.com.au/sell_your_phone/154 , The title of the page is "WeBuyback.com.au | Sell Your Phones and Tablets for Quick Cash" I would like it to be ," HTC One X 32GB" .
Is there any way to achieve this?
Hi jjalvi.
In Controller you have a ID 154.
You can do a SELECT in database and get the title of the product.
For Example (Controller):
Code:
public function view_product($id){
$header = array();
$where = array(
'id' => $id
);
$product_info = $this->db->get_where('products',$where)->row_array();
$header['page_title'] = 'WeBuyback.com.au | '.$product_info['title'];
$this->load->view('header',$header);
}
Just a detail, I think is better make database queries at models:
At model (Products_model):
PHP Code:
public function get_row($id)
{
return $this->db->get_where('products', array('id' => $id))->row();
}
At controller (Products):
PHP Code:
public function view($id)
{
$this->load->model('products_model');
$product = $this->product_model->get_row($id);
$header = array();
$header['page_title'] = 'WeBuyback.com.au | '.$product['title'];
$this->load->view('header',$header);
}
Greetings.