Welcome Guest, Not a member yet? Register   Sign In
How to call element/partial in my view file using layout library.
#1

[eluser]Kryptonian[/eluser]
Hi,

I'm using the Layout library (http://codeigniter.com/wiki/layout_library/) and I modified it.

My problem is, how can I call an element like in cakephp to my view files. What is the correct way to do it?

Can I call $this->load->view to my views?

Thanks in advance.

Cheers,
Mark
#2

[eluser]Unknown[/eluser]
First sorry for my bad English.
I am no expert in CodeIgniter, but I resolved as follows manner.

In the controller
Code:
//we asumed that $product is the array collection of products
$data['products'] = $products;
$this->layout->view("view_name",$data);

In the "view_name.php" view I only use "$this->load->view()" function
Code:
<h1>Title</h1>
&lt;?php foreach($products as $product){
    $data['product'] = $product;
    $this->load->view("partial_view",$data);
} ?&gt;

Finally in the "partial_view.php" view
Code:
<div>
  <h3>&lt;?php echo $product['name'] ?&gt;</h3>
  <p>&lt;?php echo $product['description'] ?&gt;</p>
</div>

I hope to help you.




Theme © iAndrew 2016 - Forum software by © MyBB