CodeIgniter Forums
Making a shared block with data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Making a shared block with data (/showthread.php?tid=61104)



Making a shared block with data - El Forum - 09-18-2014

[eluser]Unknown[/eluser]
I’m kind of new to this framework.

Can I know how do I make a proper shared block that contains pulled data from the database?

For example a “Featured product block” where I can located in different pages?

Product Controller

Code:
public function featured_product_block(){
  $product_array = $this->product_model->get_product();
  $data["products"] = $product_array;
  $this->load->view("blocks/product_block", $data);
}

So do I just call this controller from another controller? Or is there another way to do it?


Making a shared block with data - El Forum - 09-18-2014

[eluser]CroNiX[/eluser]
You can't call a controller from a controller. If you need to use something in multiple controllers, you should use a library or a helper.


Making a shared block with data - El Forum - 09-18-2014

[eluser]InsiteFX[/eluser]
Or use Modular Extensions

MODULAR EXTENSIONS 5.4



Making a shared block with data - El Forum - 09-18-2014

[eluser]CroNiX[/eluser]
Do you know if Wiredesignz is going to port it to CI3, or if it works in CI3? If we don't know that, I wouldn't recommend using it or it would make you have to rewrite a lot of code if/when you do upgrade. Using libraries/helpers is more foolproof as they are actually a part of CI and probably always will be.


Making a shared block with data - El Forum - 09-18-2014

[eluser]InsiteFX[/eluser]
From talking with him he told me he would port it to CI 3.0 when it is released.