<?php
namespace App\Controller;

use App\Controller\AppController;

/**
 * WlSchooltypes Controller
 *
 * @property \App\Model\Table\WlSchooltypesTable $WlSchooltypes
 *
 * @method \App\Model\Entity\WlSchooltype[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
 */
class WlSchooltypesController extends AppController
{

    /**
     * Index method
     *
     * @return \Cake\Http\Response|void
     */
    public function index()
    {
        $wlSchooltypes = $this->paginate($this->WlSchooltypes);

        $this->set(compact('wlSchooltypes'));
    }

    /**
     * View method
     *
     * @param string|null $id Wl Schooltype id.
     * @return \Cake\Http\Response|void
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function view($id = null)
    {
        $wlSchooltype = $this->WlSchooltypes->get($id, [
            'contain' => ['Budget']
        ]);

        $this->set('wlSchooltype', $wlSchooltype);
    }

    /**
     * Add method
     *
     * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise.
     */
    public function add()
    {
        $wlSchooltype = $this->WlSchooltypes->newEntity();
        if ($this->request->is('post')) {
            $wlSchooltype = $this->WlSchooltypes->patchEntity($wlSchooltype, $this->request->getData());
            if ($this->WlSchooltypes->save($wlSchooltype)) {
                $this->Flash->success(__('The wl schooltype has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('The wl schooltype could not be saved. Please, try again.'));
        }
        $this->set(compact('wlSchooltype'));
    }

    /**
     * Edit method
     *
     * @param string|null $id Wl Schooltype id.
     * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise.
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
     */
    public function edit($id = null)
    {
        $wlSchooltype = $this->WlSchooltypes->get($id, [
            'contain' => []
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $wlSchooltype = $this->WlSchooltypes->patchEntity($wlSchooltype, $this->request->getData());
            if ($this->WlSchooltypes->save($wlSchooltype)) {
                $this->Flash->success(__('The wl schooltype has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('The wl schooltype could not be saved. Please, try again.'));
        }
        $this->set(compact('wlSchooltype'));
    }

    /**
     * Delete method
     *
     * @param string|null $id Wl Schooltype id.
     * @return \Cake\Http\Response|null Redirects to index.
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $wlSchooltype = $this->WlSchooltypes->get($id);
        if ($this->WlSchooltypes->delete($wlSchooltype)) {
            $this->Flash->success(__('The wl schooltype has been deleted.'));
        } else {
            $this->Flash->error(__('The wl schooltype could not be deleted. Please, try again.'));
        }

        return $this->redirect(['action' => 'index']);
    }
}
