-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayout.php
executable file
·128 lines (118 loc) · 2.33 KB
/
Layout.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
class Layout_Core {
protected static $instance;
protected $layout='layouts/layout';
protected $view;
protected $render_layout=true;
/**
* Singleton instance
* @return object singleton instance
* @param $layout Object[optional]
*/
public static function instance($layout=false)
{
if(is_null(self::$instance))
{
self::$instance = new self($layout);
}
return self::$instance;
}
/**
* Constructor
* @return
* @param $layout Object
*/
private function __construct($layout)
{
$layout!=FALSE AND $this->layout=$layout;
Event::add('system.post_controller',array($this,'render'));
$this->view=new View;
Kohana::$instance->view=new View;
}
/**
* Render layout, called automatically after controller
* Also renders the subview into $content
*
* @return void
*/
public function render()
{
if(Kohana::$instance->view instanceof View AND Kohana::$instance->view->kohana_filename==NULL)
{
Kohana::$instance->view->set_filename($this->view_path());
}
if($this->render_layout==true)
{
$this->view->set_filename($this->layout);
$this->view->content=Kohana::$instance->view;
$this->view->render(true);
}
else
{
if(Kohana::$instance->view instanceof View AND Kohana::$instance->view->kohana_filename!=NULL)
{
Kohana::$instance->view->render(true);
}
}
}
/**
* Returns the standard controller to view mapping
* views/controller_path/controller_name/controller_method
*
* @return string
*/
public function view_path()
{
return (Router::$controller_dir.'/'.Router::$controller.'/'.Router::$method);
}
/**
* calls render()
*
* @return unknown
*/
public function __toString()
{
return (string) $this->render();
}
/**
* Magic __get method
* @return mixed
* @param $name Object
*/
public function __get($name)
{
if(isset($this->$name))
{
return $this->$name;
}
elseif($name=='view')
{
return Kohana::$instance->view;
}
else
{
return $this->view->$name;
}
}
/**
* Magic __set method
* @return
* @param $name Object
* @param $value Object
*/
public function __set($name,$value)
{
if(isset($this->$name))
{
$this->$name=$value;
}
elseif($name=='view')
{
Kohana::$instance->view=$value;
}
else
{
$this->view->$name=$value;
}
}
}