<?php namespace App\Controllers;
use App\Models\FieldModel;
use App\Models\InvoiceModel;
use App\Models\UserModel;
use App\Models\NewsModel;
use App\Models\ScheduleModel;
use App\Models\FacultyModel;
use App\Models\CourseModel;
use App\Models\CountryModel;
use App\Models\CenterModel;
use App\Models\ApplicationModel;
use App\Models\CourseOutlineModel;
use App\Controllers\Proforma;
use App\Models\PagesModel;
class Pages extends BaseController
{

	private $cats;
	private $course;


	function __construct(){
		$facultyModel=new FacultyModel();
		$this->$cats=$facultyModel->orderBy('facultyName', 'ASC')->findAll();

	}
	
	public function create()
{
	$data['cats']=$this->$cats;
		$courseModel= new CourseModel();
		$data['trendings'] = $courseModel->join('durationtypes','courses.durationType=durationtypes.typeID')->orderBy('courseID', 'ASC')->limit(4)->findAll();

		$courseModel= new CourseModel();
		$data['recents'] = $courseModel->join('durationtypes','courses.durationType=durationtypes.typeID')->orderBy('courseID', 'DESC')->limit(4)->findAll();

		$scheduleModel = new ScheduleModel();
    $data['schedules']=$scheduleModel->getUpcomingSchedules();
    $model = new PagesModel();

    if ($this->request->getMethod() === 'post' && $this->validate([
            'title' => 'required|min_length[3]|max_length[255]',
            'body'  => 'required'
        ]))
    {
        $model->save([
            'title' => $this->request->getPost('title'),
            'slug'  => url_title($this->request->getPost('title'), '-', TRUE),
            'body'  => $this->request->getPost('body'),
        ]);

        echo view('news/success');

    }
    else
    {
        echo view('templates/header', $data);
       // echo view('<h2>This is a  sample!</h2>');
        echo view('templates/footer');
    }
}
}

