Bonjour,

mon code avec la methode MVC.
j'aimerai appeler une fonction qui contient paramètre comme fonction contient paramètre ,

-- > mon fonction principale cherche_product

-- > Controller

echo $v->cherche_product($m->get_Soucategorie(null));

-- >View
public function cherche_product($cats){
comment doit faire pour paramètre de $cats
$cats() ???
}

j'ai aucun aide comme appel un parametre(fonction) qui contient parametre ,
Je vous remercie d'avance

2 réponses


Salut @TAYANE
puis je voir ton code complet stp ?

TAYANE
Auteur

Merci @Balbert de votre aide
-- > Model
public function get_Soucategorie($cat = "NULL") {
try {

        $connection = new close_open_cn();

        $cn = $connection->open(null);

        $query = $cn->prepare("SELECT * FROM `categorie` where sous_cat = '$cat'");

        $query->execute();

        return  $query->fetchAll();

    } catch (exception $ex) {

        return $ex->getMessage();
    }
}// end function

-- > View 
 public function cherche_product($cats){
$form ="<div class='cherche-prod'>";
$form .="<div class='form-group'>";
$form .="<select class='form-control sherch'>";

foreach ($cats as $value) {
        $form .="<optgroup label=".$value[1].">";
        foreach ($cats($value[1]) as $val) { ce parametre le probleme
            $form .="<option>".$val[1]."</option>";
        }
        $form .="</optgroup>";
    }
$form .="</select>";
$form .="<div class='sous'>";
$form .="</div>";
$form .="</div>";
$form .="</div>";
return $form;

}

--> controller
include("../view/index.php"); // include view
include("../model/index.php"); // include model
$v = new v_product();
$m = new product_db();
$v->print_head("Get Product");
$v->print_header("prod");
$v->print_content($v->cherche_product($m->get_Soucategorie())); ce paramètre qui contient paramétre