Completed
Push — master ( 096fcc...a76185 )
by Hugo
04:48
created

ControllerBase::afterExecuteRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4286
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
use Phalcon\Mvc\Controller;
4
5
class ControllerBase extends Controller{
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
7
    protected $model;
8
    protected $title;
9
    protected $controller;
10
11
    public function afterExecuteRoute($dispatcher){
12
        $baseUrl = $this->baseUrl;
13
        $this->view->setVar("baseUrl", $baseUrl);
14
        $this->view->setVar("controller", $this->controller);
15
        $this->view->setVar("title", $this->title);
16
    }
17
18
    public function indexAction(){
19
        $objects = call_user_func($this->model."::find");
20
        $this->view->setVar("objects",$objects);
21
        $this->view->pick("main/index");
22
    }
23
24
    public function frmAction($id =  NULL){
25
        echo "Pas encore implémenté...";
26
    }
27
28
    public function readAction($id = NULL){
29
        if($id != null){
30
            $object = call_user_func($this->model.'::find', "id = $id");
31
            $this->view->setVar("object",$object);
32
            $this->view->pick("main/read");
33
        }
34
    }
35
36
    public function updateAction(){
37
        echo "Pas encore implémenté...";
38
    }
39
40
    public function deleteAction($id = null){
41
        $object = call_user_func($this->model.'::findFirst', "id = $id");
42
        $object->delete();
43
        $this->response->redirect("Index/index");
44
    }
45
46
    public function asAdminAction(){
47
        $user = User::findFirst("id=3");
48
        $this->session->set("user", $user);
49
        $this->response->redirect("Index/index");
50
    }
51
52
    public function asUserAction(){
53
        $user = User::findFirst("id=1");
54
        $this->session->set("user", $user);
55
        $this->response->redirect("Index/index");
56
    }
57
58
    public function logoutAction(){
59
        $this->session->destroy();
60
        $this->response->redirect("Index/index");
61
    }
62
63
}
64