Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Model (../models/Category.php)*/
- <?php
- class Category
- {
- public static function getList()
- {
- try
- {
- $db = Db::getConnection();
- $categories = $db->prepare("SELECT * FROM categories");
- $categories->execute();
- return $categories->fetchAll(PDO::FETCH_ASSOC);
- } catch (PDOException $err)
- {
- die("I can't get category list, because " . $err->getMessage());
- }
- }
- }
- ?>
- /** Controller (../controllers/AdminController.php)*/
- <?php
- class AdminController
- {
- public function actionIndex()
- {
- $categories = Category::getList();
- require_once ROOT . '/views/pages/admin/admin.php';
- return true;
- }
- }
- ?>
- /** Somewhere in View */
- ...
- <?php foreach ($categories as $category): ?>
- blablabla <?=$category['category_name']; ?>
- blablabla
- <?php endforeach; ?>
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement