{"id":104,"date":"2009-12-01T12:56:52","date_gmt":"2009-12-01T20:56:52","guid":{"rendered":"http:\/\/blog.portnumber53.com\/?p=104"},"modified":"2009-12-01T12:56:52","modified_gmt":"2009-12-01T20:56:52","slug":"a-base-controller-using-kohana-v3-0-3","status":"publish","type":"post","link":"https:\/\/blog.portnumber53.com\/index.php\/2009\/12\/01\/a-base-controller-using-kohana-v3-0-3\/","title":{"rendered":"A base controller using Kohana v3.0.3"},"content":{"rendered":"<p>Here&#8217;s how I created a base controller for websites I develop using Kohana v3<\/p>\n<p>1. create a website config file ( application\/config\/website.php ):<\/p>\n<pre class=\"brush:php\">&lt;?php defined('SYSPATH') OR die('No Direct Script Access');\nreturn array( 'site_name' =&gt; 'Example site',);\n&lt;?php defined('SYSPATH') OR die('No Direct Script Access');\nreturn array(\n      'site_name'  =&gt; 'Example site',\n);<\/pre>\n<p>2. Create a basic CSS file for your site ( html\/template\/default\/css\/style.css ):<\/p>\n<pre class=\"brush:css\">body {\n      font-size: 14px;\n}<\/pre>\n<p>3. Create the website controller ( application\/classes\/controller\/website.php ):<\/p>\n<pre class=\"brush:php\">&lt;?php defined('SYSPATH') or die('No direct script access.');\nclass Controller_Website extends Controller_Template {\n      public $template  = '';\n      public $page_title  = '';\n      public $site_name  = '';\n      public $template_name  = '';\n      public $styles  = array();\n      public $scripts  = array();\n      public function before()\n      {\n            $this-&gt;auto_render = false;\n            parent::before();\n            $this-&gt;auto_render = true;\n            $this-&gt;template_name = 'default';\n            $this-&gt;site_name = kohana::config('website.site_name');\n            $this-&gt;styles = array(\n            'template\/' . $this-&gt;template_name . '\/css\/style.css' =&gt; 'screen',\n      );\n      $this-&gt;scripts = array(\n            'http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.3.2\/jquery.min.js',\n      );\n      $this-&gt;template = View::factory('template\/' . $this-&gt;template_name . '\/default');\n      if ($this-&gt;auto_render)\n      {\n            $this-&gt;template-&gt;bind('page_title', $this-&gt;page_title)\n            -&gt;bind('site_name', $this-&gt;site_name)\n            -&gt;bind('styles', $this-&gt;styles)\n            -&gt;bind('scripts', $this-&gt;scripts)\n      ;\n      }\n      }\n      public function action_index()\n  {\n  \/\/$this-&gt;request-&gt;response = 'hello, world!';\n  $this-&gt;template-&gt;content= '&lt;!--Default website controller, you don't want to access this one--&gt;';\n  }\n  public function after()\n  {\n  $this-&gt;template-&gt;bind('styles', $this-&gt;styles)\n  -&gt;bind('scripts', $this-&gt;scripts)\n  ;\n  parent::after();\n  }\n} \/\/ End Website<\/pre>\n<p>4. Create the template file ( application\/views\/template\/default\/default.php ):<\/p>\n<pre class=\"brush:html\">&lt;html&gt;\n  &lt;head&gt;\n  &lt;meta charset=\"utf-8\" \/&gt;\n  &lt;title&gt;&lt;?php echo empty($page_name) ? '' : \"$page_name - \"; ?&gt;&lt;?php echo empty($site_title) ? '' : $site_name; ?&gt;&lt;\/title&gt;\n  &lt;?php foreach ($styles as $file =&gt; $type) echo HTML::style($file, array('media' =&gt; $type)) . \"n\"; ?&gt;\n  &lt;?php foreach ($scripts as $file) echo HTML::script($file) . \"n\"; ?&gt;\n  &lt;\/head&gt;\n&lt;body&gt;\n  &lt;?php echo empty($content) ? '' : $content; ?&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s how I created a base controller for websites I develop using Kohana v3 1. create a website config file ( application\/config\/website.php ): &lt;?php defined(&#8216;SYSPATH&#8217;) OR die(&#8216;No Direct Script Access&#8217;); return array( &#8216;site_name&#8217; =&gt; &#8216;Example site&#8217;,); &lt;?php defined(&#8216;SYSPATH&#8217;) OR die(&#8216;No Direct Script Access&#8217;); return array( &#8216;site_name&#8217; =&gt; &#8216;Example site&#8217;, );&#8230; <a class=\"continue-reading-link\" href=\"https:\/\/blog.portnumber53.com\/index.php\/2009\/12\/01\/a-base-controller-using-kohana-v3-0-3\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-104","post","type-post","status-publish","format-standard","hentry","category-kohana"],"_links":{"self":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/comments?post=104"}],"version-history":[{"count":0,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}