<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Language" content="en-us" /> <title><?php echo $title;?></title> <meta name="keywords" content="<?php echo $meta_keywords;?>" /> <meta name="description" content="<?php echo $meta_description;?>" /> <meta name="copyright" content="<?php echo $meta_copywrite;?>" /> <?php foreach($styles as $file => $type) { echo HTML::style($file, array('media' => $type)), "\n"; }?> <?php foreach($scripts as $file) { echo HTML::script($file, NULL, TRUE), "\n"; }?> </head> <body> <div id="container"> <?php echo $header;?> <?php echo $content;?> <?php echo $footer;?> </div> </body> </html>
<?php defined('SYSPATH') or die('No direct script access.'); class Controller_DefaultTemplate extends Controller_Template { public $template = 'templates/default'; /** * Initialize properties before running the controller methods (actions), * so they are available to our action. */ public function before() { // Run anything that need ot run before this. parent::before(); if($this->auto_render) { // Initialize empty values $this->template->title = ''; $this->template->meta_keywords = ''; $this->template->meta_description = ''; $this->template->meta_copywrite = ''; $this->template->header = ''; $this->template->content = ''; $this->template->footer = ''; $this->template->styles = array(); $this->template->scripts = array(); } } /** * Fill in default values for our properties before rendering the output. */ public function after() { if($this->auto_render) { // Define defaults $styles = array('assets/css/reset.css' => 'screen'); $scripts = array('http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'); // Add defaults to template variables. $this->template->styles = array_reverse(array_merge($this->template->styles, $styles)); $this->template->scripts = array_reverse(array_merge($this->template->scripts, $scripts)); } // Run anything that needs to run after this. parent::after(); } }
Helpers are handy features that are designed to help you with development.
They are similar to library functions, but there is a slight difference. In the case of libraries, it is necessary to create an instance of the library class in order to use its methods. Helpers are static class methods that are automatically loaded by the framework, so there is no need to perform additional actions.
class Controller_Ko3 extends Controller
class Controller_Ko3 extends Controller_DefaultTemplate
public function action_index() { $ko3_inner = array(); $ko3 = array(); $this->template->title = 'Kohana 3.0'; View::set_global('x', 'This is a global variable'); $ko3_inner['content'] = 'We have more data'; $ko3['content'] = 'We have data'; $ko3['ko3_inner'] = View::factory('blocks/ko3_inner', $ko3_inner) ->render(); $this->template->content = View::factory('pages/ko3', $ko3); }
<h1>This is my first view</h1> <?php echo $content;?> <?php echo $ko3_inner; ?> <br/><?php echo $x;?>
public function action_index() { $ko3_inner = array(); $ko3 = array(); $this->template->title = 'Kohana 3.0'; $this->template->meta_keywords = 'PHP, Kohana, KO3, Framework'; $this->template->meta_description = 'A test of of the KO3 framework'; $this->template->styles = array('assets/css/red.css' => 'screen'); $this->template->scripts = array('assets/js/jqtest.js'); View::set_global('x', 'This is a global variable'); $ko3_inner['content'] = 'We have more data'; $ko3['content'] = 'We have data'; $ko3['ko3_inner'] = View::factory('blocks/ko3_inner', $ko3_inner) ->render(); $this->template->content = View::factory('pages/ko3', $ko3); }
h1 { color: #FF0000; }
$("document").ready(function() { alert('Hello Kohana!'); });
Source: https://habr.com/ru/post/111537/
All Articles