public function getPosts($categoryID)
 {
     $category = $this->categoryRepository->findById($categoryID);
     $posts = $this->blogRepository->model->where('category_id', $category->id)->paginate(5);
     $categories = $this->categoryRepository->getPostCategories()->get();
     $this->title = $category->name;
     $this->render('site.category.blogs', compact('posts', 'categories'));
 }
Example #2
0
 public function setCategory($value)
 {
     if ($value instanceof Category) {
         $this->_orm->category_id = $value->id;
         return true;
     }
     $category = Category::findById($value);
     if ($category) {
         $this->_orm->category_id = $value;
         return true;
     }
     throw new Exception("Category does not exist");
 }
Example #3
0
 public static function get()
 {
     return function ($req, $res) {
         $res->header('Content-Type', 'application/json');
         $model = Category::findById($req->id);
         if ($model) {
             if ($req->method('post')) {
                 $data = json_decode(file_get_contents("php://input"));
                 $model->name = $data->name;
                 $model->description = $data->description;
                 $model->save();
                 echo $model;
             } elseif ($req->method('delete')) {
                 $model->delete();
                 $res->code(200);
             } else {
                 echo $model;
             }
         } else {
             $res->code(404);
         }
     };
 }
 public function getPosts($id)
 {
     $posts = $this->categoryRepository->findById($id)->posts;
     return $posts;
 }
Example #5
0
            <div class="price">
                <?php 
        echo $product->price;
        ?>
  
            </div>
            <div class="quantity">
                <?php 
        echo $product->quantity;
        ?>
  
            </div>
            <div class="category-title">
                <?php 
        $category = new Category();
        echo $category->findById($connect, $product->category_id)->title;
        ?>
  
            </div>
            <div class="controls">
                <a class="a-edit" href="edit.php?productId=<?php 
        echo $product->id;
        ?>
">Edit</a>
                <a class="a-del" href="delete.php?productId=<?php 
        echo $product->id;
        ?>
">Delete</a>
            </div>
        </li>
        <?php 
Example #6
0
<?php

require "../category.php";
$category = Category::findById(3);
print_r($category->products);
echo $category->products[1]->as_joined_json();