Example implementation of a controller
This commit is contained in:
parent
326b9cb56b
commit
95ad2e1d6a
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
final class HelloworldController
|
||||
{
|
||||
public function defaultAction()
|
||||
{
|
||||
$O_helloworld = new Helloworld();
|
||||
View::show('helloworld/view', array('helloworld' => $O_helloworld->getMessage()));
|
||||
|
||||
}
|
||||
|
||||
public function testformAction(Array $A_urlParams = null, Array $A_postParams = null)
|
||||
{
|
||||
|
||||
View::show('helloworld/testform', array('formData' => $A_postParams));
|
||||
|
||||
}
|
||||
|
||||
}
|
46
Controllers/RecipeController.php
Normal file
46
Controllers/RecipeController.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
final class RecipeController
|
||||
{
|
||||
|
||||
public function viewAction(Array $A_urlParams = null, Array $A_postParams = null)
|
||||
{
|
||||
if(count($A_urlParams)!=1){
|
||||
echo "404";
|
||||
return;
|
||||
}
|
||||
|
||||
$O_recipeModel = new RecipeModel();
|
||||
$O_recipe = $O_recipeModel->getByID($A_urlParams[0]);
|
||||
if($O_recipe === null){
|
||||
echo "404";
|
||||
return;
|
||||
}
|
||||
|
||||
$O_ingredientModel = new IngredientModel();
|
||||
$A_ingredients = $O_ingredientModel->searchByRecipe($O_recipe["id"]);
|
||||
|
||||
$O_userModel = new UserModel();
|
||||
$A_authorName = $O_userModel->getNameByID($O_recipe["author_id"]);
|
||||
|
||||
$O_userModel = new DifficultyModel();
|
||||
$A_difficultyName = $O_userModel->getByID($O_recipe["difficulty_id"]);
|
||||
|
||||
$A_returnArray = array(
|
||||
"recipe_name" => $O_recipe["name"],
|
||||
"recipe_desc" => $O_recipe["desc"],
|
||||
"author_name" => $A_authorName,
|
||||
"recipe_ingredients" => $A_ingredients,
|
||||
"difficulty_name" => $A_difficultyName,
|
||||
);
|
||||
|
||||
View::show("recipe/view", $A_returnArray);
|
||||
|
||||
// print_r($A_urlParams);
|
||||
// $O_recetteModel = new RecipeIngredientsModel();
|
||||
// $O_recetteModel->getByID("");
|
||||
// View::show('helloworld/testform', array('formData' => $A_postParams));
|
||||
|
||||
}
|
||||
|
||||
}
|
14
Models/DifficultyModel.php
Normal file
14
Models/DifficultyModel.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
final class DifficultyModel
|
||||
{
|
||||
|
||||
public function getByID($I_difficuly_id)
|
||||
{
|
||||
if ($I_difficuly_id == 1) {
|
||||
return "Facile";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
|
||||
final class Helloworld
|
||||
{
|
||||
private $_S_message = "Hello World";
|
||||
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->_S_message ;
|
||||
}
|
||||
|
||||
}
|
21
Models/IngredientModel.php
Normal file
21
Models/IngredientModel.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
final class IngredientModel
|
||||
{
|
||||
|
||||
public function searchByRecipe($I_recipe_id)
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
"id" => 1,
|
||||
"name" => "oeuf",
|
||||
"quantity" => "6",
|
||||
),
|
||||
array(
|
||||
"id" => 2,
|
||||
"name" => "lait",
|
||||
"quantity" => "1/2L",
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
21
Models/RecipeModel.php
Normal file
21
Models/RecipeModel.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
final class RecipeModel
|
||||
{
|
||||
|
||||
public function getByID($I_id)
|
||||
{
|
||||
if ($I_id == 36) {
|
||||
return array(
|
||||
"id" => 36,
|
||||
"name" => "Ma recette num 36",
|
||||
"desc" => "Une brève description de la recette 36",
|
||||
"recipe" => "Etape 1\nEtape 2\nEtape 3",
|
||||
"difficulty_id" => 1,
|
||||
"author_id" => 1,
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
14
Models/UserModel.php
Normal file
14
Models/UserModel.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
final class UserModel
|
||||
{
|
||||
|
||||
public function getNameByID($I_id)
|
||||
{
|
||||
if ($I_id == 1) {
|
||||
return "Thomas";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
echo "<p>" . $A_view['helloworld'] . "</p>";
|
10
Views/recipe/view.php
Normal file
10
Views/recipe/view.php
Normal file
@ -0,0 +1,10 @@
|
||||
<p> <?= $A_view["recipe_name"] ?> </p>
|
||||
<p> Auteur: <?= $A_view["author_name"] ?> </p>
|
||||
<p> Difficulté: <?= $A_view["difficulty_name"] ?> </p>
|
||||
<p> Ingrédients: </p>
|
||||
<?php
|
||||
|
||||
foreach($A_view["recipe_ingredients"] as $i){
|
||||
echo "<p> {$i['name']}: {$i['quantity']} </p>";
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user