Show 3 random recipes on home page
This commit is contained in:
parent
d356a4d816
commit
752796fab3
@ -5,26 +5,8 @@ final class DefaultController
|
|||||||
|
|
||||||
public function defaultAction(Array $A_urlParams = null, Array $A_postParams = null)
|
public function defaultAction(Array $A_urlParams = null, Array $A_postParams = null)
|
||||||
{
|
{
|
||||||
$array_recipes = array(
|
$A_recipes = RecipeModel::getRandomRecipes(3);
|
||||||
array(
|
|
||||||
"RECIPE_LINK" => "/recipe/view/1",
|
View::show("home/view", array("RECIPES" => $A_recipes));
|
||||||
"NAME" => "Pâte à crêpe",
|
|
||||||
"IMG_LINK" => "/static/img/recipes/1.jpg",
|
|
||||||
"NOTE" => "4.5"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"RECIPE_LINK" => "/recipe/view/1",
|
|
||||||
"NAME" => "Pâte à crêpe",
|
|
||||||
"IMG_LINK" => "/static/img/recipes/1.jpg",
|
|
||||||
"NOTE" => "4.5"
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
"RECIPE_LINK" => "/recipe/view/1",
|
|
||||||
"NAME" => "Pâte à crêpe",
|
|
||||||
"IMG_LINK" => "/static/img/recipes/1.jpg",
|
|
||||||
"NOTE" => "4.5"
|
|
||||||
),
|
|
||||||
);
|
|
||||||
View::show("home/view", $array_recipes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,4 +191,23 @@ final class RecipeModel
|
|||||||
|
|
||||||
return $A_recipes;
|
return $A_recipes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getRandomRecipes($I_n)
|
||||||
|
{
|
||||||
|
$O_model = Model::get();
|
||||||
|
$stmt = $O_model->prepare("
|
||||||
|
SELECT * FROM RECIPE
|
||||||
|
ORDER BY RAND()
|
||||||
|
LIMIT :n
|
||||||
|
");
|
||||||
|
$stmt->bindParam("n", $I_n, PDO::PARAM_INT);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$A_recipes = array();
|
||||||
|
foreach($stmt->fetchAll() as $row){
|
||||||
|
array_push($A_recipes, self::createFromRow($row, $row["ID"]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $A_recipes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
<a href="<?= $A_view["RECIPE_LINK"]?>">
|
<?php
|
||||||
<img src="<?= $A_view["IMG_LINK"] ?>" alt="<?= $A_view["NAME"]?>">
|
$O_recipe = $A_view["RECIPE"];
|
||||||
|
?>
|
||||||
|
<a href="<?= $O_recipe->getLink() ?>">
|
||||||
|
<img src="<?= $O_recipe->getImageLink() ?>" alt="<?= $O_recipe->S_NAME ?>">
|
||||||
<section>
|
<section>
|
||||||
<h2> <?= $A_view["NAME"]?> </h2>
|
<h2> <?= $O_recipe->S_NAME ?> </h2>
|
||||||
<p> <?= $A_view["NOTE"]?> </p>
|
<p> <?= $O_recipe->I_NOTE ?> </p>
|
||||||
</section>
|
</section>
|
||||||
</a>
|
</a>
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
<section>
|
<section>
|
||||||
<h1> Nos idées recettes: </h1>
|
<h1> Nos idées recettes: </h1>
|
||||||
<?php
|
<?php
|
||||||
foreach ($A_view as $recipe){
|
foreach ($A_view["RECIPES"] as $O_recipe){
|
||||||
View::show("common/recipe", $recipe);
|
View::show("common/recipe", array("RECIPE" => $O_recipe));
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</section>
|
</section>
|
||||||
|
Loading…
Reference in New Issue
Block a user