Good day community, I hope you can help me with this little problem that I have ... I just started with this framework and I have the following problem. It is a site in which I intend to show products and categories of a database ... the code of the view, model and controller I leave it below. Problem: What I want to do is in the products view send the data of the categories, products and also page, so you can see in my code I had to separate a view of categories and other products to achieve it temporarily, but at the time of wanting to put the product page I stumble again with the problem: / Expected result: use a single view of products that have categories, products and pages.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Principal_ci extends CI_Controller {
public function index()
{
$this->load->model('categorias_mdl');
$result = $this->categorias_mdl->getCategorias();
$cat = array('categorias' => $result);
$this->load->model('productos_mdl');
$result = $this->productos_mdl->getProductos();
$prod = array('productos' => $result);
$this->load->view('header');
$this->load->view('categorias', $cat);
$this->load->view('principal', $prod);
$this->load->view('footer');
}
}
class Productos_mdl extends CI_Model {
public function getProductos($limite=9)
{
return $this->db->get('producto', $limite);
}
}
// Fragmento de la vista de como saco los datos actualmente
<?php foreach ($categorias->result() as $categoria) { ?>
<a href="#" class="list-group-item"><?= $categoria->nom_cat ?></a>
<?php } ?>