I am new to MVC, I am transferring a project written in a non-MVC style to MVC, but I am stuck in a problem when it is necessary to call a model function in a view.
Scenario:
Table 1 - Products:
contains product_id, product_nameetc., and for each product there may be several versions.
Table2 - Versions:
contains version_id, version_name..., product_idetc.
Now, in the view, I show the products, and under each heading of the product I have to display a list of versions of this product, in a style different from MVC, it was quite simple, I can use the following code fragment in the view:
foreach ($product as $row)
{
echo $row['product_name'];
if ($main->getVersionList($vresult,$row["product_id"]))
{
foreach ($vresult as $vrow)
{
echo $vrow['version_name'];
}
}
}
Product , Version, , ?
Update:
( ), :
$this->load->model ( 'product_mod' );
$data ['products'] = $this->product_mod->getProductList ();
$data ['versions'] = array ();
foreach ( $data ['products'] as $product )
{
$data ['versions'] [$product['product_id']] = $this->product_mod->getVersionList ( $product['product_id'] );
}