1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Phalcon\Mvc\Controller; |
4
|
|
|
|
5
|
|
|
class ControllerBase extends Controller{ |
|
|
|
|
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
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.