Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Several additions:

  - Altered config handling. Deleted all dot-notation stuff and used
    the config like it should with Kohana 3.2
  - Added a pre-render method for stuff that needs to be done after
    setting the config array but before rendering of the view
  • Loading branch information...
commit 47f857eb1666bea1a9cec958e1d1b69ce7f6fd8a 1 parent 9c8c38f
@Luwe authored
Showing with 34 additions and 26 deletions.
  1. +26 −16 classes/ljcore/view/core.php
  2. +8 −10 classes/ljcore/view/default.php
View
42 classes/ljcore/view/core.php
@@ -15,28 +15,38 @@
abstract class Ljcore_View_Core extends Kostache_Layout {
/**
+ * Holds the config array
+ * @var array
+ */
+ public $config;
+
+ /**
* Config file to get initial layout settings from
* @var string
*/
- protected $_layout_config = 'website';
-
+ protected $_config_file = 'website';
+
/**
- * Add initial settings from a config file to an existing array
- *
- * @param mixed array to prepend initial settings to
- * @param mixed config file
- * @param mixed config variable (dotnotation enabled type.subtype etc.)
- * @return array
+ * Overloaded render method to include config setting and pre_rendering
+ *
+ * @return string
*/
- protected function _add_initial_settings(array $var, $type = 'css')
+ public function render()
{
- $type = ($type) ? '.'. (string) $type : '';
-
- // Check if initial array exists, otherwise send back original $var
- if ( ! ($initial = Kohana::$config->load($this->_layout_config.$type)))
- return $var;
+ $this->config = Kohana::$config->load($this->_config_file)->as_array();
+ $this->pre_render();
+
+ return parent::render();
+ }
- return array_merge($initial, $var);
+ /**
+ * Pre-render method
+ *
+ * @return void
+ */
+ public function pre_render()
+ {
+ // Everything that needs to happen after config, but before rendering
}
-
+
}
View
18 classes/ljcore/view/default.php
@@ -36,7 +36,7 @@
*/
public function title()
{
- return (string) Kohana::$config->load($this->_layout_config.'.title');
+ return (string) $this->config['title'];
}
/**
@@ -46,8 +46,8 @@ public function title()
*/
public function favicon()
{
- return URL::site(Kohana::$config->load('media.images')
- .Kohana::$config->load($this->_layout_config.'.favicon'), NULL, FALSE);
+ return URL::site(Kohana::$config->load('media')->get('images')
+ .$this->config['favicon'], NULL, FALSE);
}
/**
@@ -58,11 +58,10 @@ public function favicon()
public function scripts()
{
// Add initial global scripts
- $this->_scripts = $this->_add_initial_settings($this->_scripts, 'files.js');
-
+ $raw = $this->config['files']['js'] + $this->_scripts;
$scripts = array();
- foreach ($this->_scripts as $file)
+ foreach ($raw as $file)
{
$file = $this->_format_media_uri($file, 'js');
$scripts[] = $file;
@@ -79,11 +78,10 @@ public function scripts()
public function stylesheets()
{
// Add initial global stylesheets
- $this->_stylesheets = $this->_add_initial_settings($this->_stylesheets, 'files.css');
-
+ $raw = $this->config['files']['css'] + $this->_stylesheets;
$stylesheets = array();
- foreach ($this->_stylesheets as $stylesheet)
+ foreach ($raw as $stylesheet)
{
$file = $this->_format_media_uri($stylesheet['file'], 'css');
$stylesheets[] = array('file' => $file, 'media' => $stylesheet['media']);
@@ -108,7 +106,7 @@ protected function _format_media_uri($file, $extension = 'css')
// Check if filename has protocol
if ( ! strchr($file, '://'))
{
- $file = URL::site(Kohana::$config->load('media.'.$extension).$file, NULL, FALSE);
+ $file = URL::site(Kohana::$config->load('media')->get($extension).$file, NULL, FALSE);
}
return $file;
Please sign in to comment.
Something went wrong with that request. Please try again.