Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app
- -- controllers
- ---- MainController.php
- ---- PostController.php
- -- core
- ---- App.php
- ---- Controller.php
- ---- Model.php
- ---- View.php
- -- models
- ---- PostModel
- -- views
- ---- posts.php
- .htaccess
- index.php
- // View.php
- <?php
- class View
- {
- public function render($template, $data = null)
- {
- include 'app/views/'.$template;
- }
- }
- // Model.php
- <?php
- class Model
- {
- public $connect;
- public function __construct()
- {
- $this->connect = new PDO('mysql:host=localhost;dbname=app', 'root', '');
- }
- }
- // Controller.php
- <?php
- class Controller
- {
- public $view;
- public $model;
- public function __construct()
- {
- $this->view = new View();
- $this->model = new Model();
- }
- }
- // PostModel.php
- <?php
- class PostModel extends Model
- {
- public function getPosts()
- {
- $this->connect->query('SELECT * FROM articles')->fetchAll(PDO::FETCH_OBJ);
- }
- }
- // PostController
- <?php
- class PostController extends Controller
- {
- public function __construct()
- {
- $this->model = new PostModel();
- $this->view = new View();
- }
- public function indexAction()
- {
- $posts = $this->model->getPosts();
- $this->view->render('posts.php', $posts);
- }
- }
- // posts.php
- <?php foreach ($posts as $post): ?>
- <h1><?= $post->title ?></h1>
- <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement