controller_main.php 754 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. class controller_main extends Controller
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. if(empty($_SESSION['user'])){
  8. header('Location: /user/login');
  9. }
  10. $this->model = new Model_main();
  11. }
  12. function index()
  13. {
  14. include 'app/models/model_user.php';
  15. $users_model = new Model_user();
  16. $data['users'] = $users_model->get_users();
  17. $data['posts'] = $this->model->get_posts();
  18. $this->view->generate('main_view.php', $data);
  19. }
  20. public function createpost(){
  21. if(isset($_POST['caption'], $_POST['post'])){
  22. $this->model->create_post($_POST['caption'], $_POST['post']);
  23. }
  24. header('Location: /');
  25. }
  26. }