/
layout.php
executable file
·89 lines (76 loc) · 2.53 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
<?php defined('SYSPATH') or die('No direct script access.');
/*
* Class: Core_Controller_Layout
* Extension of Core_Controller_Lattice which handles automatic wrapping of the main request in header and footer layout.
* Extend this class and set $_aactions_that_get_layout with actions that should always be wraped with the layout specified in their config.
* In the future, config could have a mapping of actions to layouts, if necessary.
* Auto wrapping can be manually bypassed by calling the html action as html/controller/action/etc.
*/
class Core_Controller_Layout extends Core_Controller_Lattice {
protected $_actions_that_get_layout = array();
protected $sub_request;
public function after()
{
if ($this->request == Request::initial() )
{
if (in_array($this->request->action(), $this->_actions_that_get_layout))
{
$this->wrap_with_layout();
}
}
}
/*
* Function: output_layout
* Wrap the response in its configured layout
*/
public function wrap_with_layout($layout=NULL)
{
if ($layout==NULL)
{
// set layout - read from config file
$layout = Kohana::config(strtolower($this->request->controller()) . '.layout');
if ( ! $layout)
{
throw new Kohana_Exception("Layout controller subclass :controller configured to layout action :action, but no layout set in configuration",
array(
':controller'=>$this->request->controller(),
':action'=>$this->request->action()
));
}
}
$layout_view = View::Factory($layout);
if (is_array(Kohana::config($layout.'.resources') ) )
{
foreach (Kohana::config($layout.'.resources') as $key => $paths)
{
foreach ($paths as $path)
{
$this->resources[$key][$path] = $path;
}
}
}
// build js and css
$stylesheet = '';
foreach ($this->resources['librarycss'] as $css)
{
$stylesheet .= HTML::style($css)."\n ";
}
foreach ($this->resources['css'] as $css)
{
$stylesheet .= HTML::style($css)."\n ";
}
$layout_view->stylesheet = $stylesheet;
$javascript = '';
foreach ($this->resources['libraryjs'] as $js)
{
$javascript .= HTML::script($js)."\n ";
}
foreach ($this->resources['js'] as $js)
{
$javascript .= HTML::script($js)."\n ";
}
$layout_view->javascript = $javascript;
$layout_view->body = $this->response->body();
$this->response->body($layout_view->render());
}
} // End Welcome