コード例 #1
0
ファイル: FoodItems.php プロジェクト: yoghurtprince/my-recipe
 /**
  * @param string|null $itemName
  * @param Item $item
  */
 public function offsetSet($itemName, $item)
 {
     if (is_null($itemName)) {
         if (!$item instanceof FoodItem) {
             $item = new FoodItem($item);
         }
         $itemName = $item->getName();
     }
     $this->items[$itemName] = $item;
 }
コード例 #2
0
ファイル: index.php プロジェクト: JoshAllan/todo-example
    <head>
        <meta charset="UTF-8">
        <title></title>
        <?php 
include 'templates/includes.php';
?>
        <?php 
// Declare the post variables we will be looking for
$args = array("_id" => FILTER_SANITIZE_STRING, "description" => FILTER_SANITIZE_STRING);
// Get our post variables using the arguments above (this method is much safer than $_POST)
$post_vars = filter_input_array(INPUT_POST, $args, false);
// Get the action veriable from our post data
$action = filter_input(INPUT_POST, "action", FILTER_SANITIZE_STRING);
// Create our Todo object. If the _id sent in the post data isn't set then the Todo is blank
$todo = new Todo($post_vars["_id"]);
$foodMenu = new FoodItem($post_vars["_id"]);
// Typical switch statement calling our functions from the Todo object
switch ($action) {
    case "remove":
        $todo->delete();
        break;
    case "add":
        $foodMenu->addToMenu();
        break;
    case "edit":
        $todo->setDescription($post_vars["description"]);
        $todo->store();
        break;
    case "done":
        $todo->done();
        $todo->store();
コード例 #3
0
ファイル: update.php プロジェクト: JoshAllan/todo-example
    <head>
        <meta charset="UTF-8">
        <title></title>
        <?php 
include 'templates/includes.php';
?>
        <?php 
// Declare the post variables we will be looking for
$args = array("_id" => FILTER_SANITIZE_STRING, "description" => FILTER_SANITIZE_STRING);
// Get our post variables using the arguments above (this method is much safer than $_POST)
$post_vars = filter_input_array(INPUT_POST, $args, false);
// Get the action veriable from our post data
$action = filter_input(INPUT_POST, "action", FILTER_SANITIZE_STRING);
// Create our Todo object. If the _id sent in the post data isn't set then the Todo is blank
$todo = new Todo($post_vars["_id"]);
$foodMenu = new FoodItem($post_vars["_id"]);
// Typical switch statement calling our functions from the Todo object
switch ($action) {
    case "remove":
        $todo->delete();
        break;
    case "add":
        $todo->createTodo($post_vars["description"]);
        break;
    case "edit":
        $todo->setDescription($post_vars["description"]);
        $todo->store();
        break;
    case "done":
        $todo->done();
        $todo->store();