/
DefaultController.php
82 lines (62 loc) · 1.95 KB
/
DefaultController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
use t41\Core\Module;
/**
* DefaultController
*
* @author
* @version
*/
use t41\Core\Layout,
t41\ObjectModel\ObjectModel,
t41\ObjectModel\Collection,
t41\View;
require_once 'Zend/Controller/Action.php';
abstract class t41_DefaultController extends Zend_Controller_Action {
protected $_module;
protected $_resource;
public function init() {
// Just in cas something goes wrong before the end
// @todo replace with a setTemplate() in t41\Exception
View::setTemplate('default.html');
// get page identifiers (module, controller and action)
Layout::$module = $this->_getParam('module');
Layout::$controller = $this->_getParam('controller');
Layout::$action = $this->_getParam('action');
// provide controller with basic information about the current module
foreach (Module::getConfig() as $vendor => $modules) {
foreach ($modules as $key => $module) {
if (isset($module['controller']) && Layout::$module == $module['controller']['base']) {
$this->_module = 'app/' . $vendor . '/' . $key;
Layout::$vendor = $vendor;
Layout::$moduleKey = $key;
$resource = Layout::$controller;
if (Layout::$action) $resource .= '/' . Layout::$action;
if (isset($module['controller']['items'])) {
foreach ($module['controller']['items'] as $controller) {
if ($this->_getCurrentItem($resource, $controller) == true) break;
}
}
if (isset($module['controllers_extends'])) {
foreach ($module['controllers_extends'] as $controller) {
if ($this->_getCurrentItem($resource, $controller['items']) == true) break;
}
}
break;
}
}
}
}
protected function _getCurrentItem($resource,$items)
{
foreach ($items as $key => $item) {
if ($key == $resource) {
$this->_resource = $item['label'];
return true;
}
if (isset($item['items'])) {
return $this->_getCurrentItem($resource, $item['items']);
}
}
return false;
}
}