
<?php

    class Courses extends Controller {
      

        private $_courseModel;
        private $data;
        
        public function __construct() {
            $this->_courseModel = $this->model('CourseModel');
        }

        public function index() {
            $this->data['courses'] = $this->_courseModel->getAllCourses();
            $this->view('Manage/courses/index', $this->data);
        }

        public function create() {
           $this->view('Manage/courses/new');
        }

        public function edit($id) {
            $this->data['courses'] = $this->_courseModel->getCourseById($id);
            $this->view('Manage/courses/edit', $this->data);
        }

        public function update() {
            $POST = $_POST;
            $this->data['courses'] = $this->_courseModel->getAllCourses();
            $this->_courseModel->updateCourse($POST['codigoactual'], $POST);
            redirect('/Courses/index');
        }

        public function persist() {
            $POST = $_POST;
            $this->_courseModel->createCourse($POST);
            redirect('/Courses/index');
        }
    }