[eluser]greedyman[/eluser]
I have a structure as below, it's in views folder:
Quote:views
--user folder
----include folder
--------header.php
--------footer.php
----welcome.php
----about.php
----account.php
----etc.php
I include header.php and footer.php into every other file in user folder (about.php, account.php, ...etc). In user controller I put some codes in default method:
Code:
public function index() {
$this->load->model('product_model');
$data['categories'] = $this->product_model->get_all_category();
$data['new_products'] = $this->product_model->get_new_products();
$data['sale_products'] = $this->product_model->get_sale_products();
$data['random_products1'] = $this->product_model->get_random_products();
$data['random_products2'] = $this->product_model->get_random_products();
$this->load->view('user/welcome', $data);
}
Of course, it's working normally. My problem here is, I have a lot of page and it means that I have to write again code many times. Example:
Code:
public function account() {
$this->load->model('product_model');
$data['account'] = $this->product_model->get_account();
$data['new_products'] = $this->product_model->get_new_products();
$data['sale_products'] = $this->product_model->get_sale_products();
$data['random_products1'] = $this->product_model->get_random_products();
$data['random_products2'] = $this->product_model->get_random_products();
$this->load->view('user/account', $data);
}
public function details() {
$this->load->model('product_model');
$data['details'] = $this->product_model->get_details();
// used for footer.php
$data['new_products'] = $this->product_model->get_new_products();
$data['sale_products'] = $this->product_model->get_sale_products();
$data['random_products1'] = $this->product_model->get_random_products();
$data['random_products2'] = $this->product_model->get_random_products();
// end
$this->load->view('user/details', $data);
}
// etc...
I have other way, I don't use parse parameter and put directly code into footer.php:
Code:
<div class="right_box">
<div class="title">
<span class="title_icon">
<img src="<?php echo base_url();?>assets/images/bullet5.gif" alt="" title="" />
</span>
Random products
</div> <!-- end .title -->
<ul class="list">
<?php
$getRamdomProducts1 = mysql_query("SELECT * FROM product ORDER BY RAND() LIMIT 11");
while ($row1 = mysql_fetch_assoc($getRamdomProducts1)) {
?>
<li>
<a href=""><?php echo $row1['name']; ?></a>
</li>
<?php
}
?>
</ul>
<div class="title">
<span class="title_icon">
<img src="<?php echo base_url();?>assets/images/bullet6.gif" alt="" title="" />
</span>
Random products
</div> <!-- end .title -->
<ul class="list">
<?php
$getRamdomProducts2 = mysql_query("SELECT * FROM product ORDER BY RAND() LIMIT 10");
while ($row2 = mysql_fetch_assoc($getRamdomProducts2)) {
?>
<li>
<a href="#"><?php echo $row2['name']; ?></a>
</li>
<?php
}
?>
</ul>
</div> <!-- end .right_box -->
I think this way is not nice, have you other solution?