Why does Kohana doesn't read my CSS? -


my website www.kipclip.com , it's running on kohana. created new rental page. it's not taking css , js files. tried find how included or if kohana has special method that. still not successful. have idea regarding this?

a quick , dirty way tack on name of script(s) , style(s) in view you're implementing using regular html script , style tags , go on there.

but, if don't quick , dirty, , prefer better , more concrete, if use kohana 3.2, can following. haven't tried on older or newer versions, may or may not work in them (if try port version, consult transitioning document relative version in question wish port):

/** *      /application/classes/controller/application.php */ abstract class controller_application extends controller_template {      public function before() {         parent::before();          if($this->auto_render) {             //initialize empty values use other derived classes             $this->template->site_name = '';//this psuedo-global set in class             $this->template->title = '';//this set controller , action             $this->template->content = ''; //this set controller , action             $this->template->styles = array();             $this->template->scripts = array();             $this->template->admin_scripts = array();         }     }          /**      * after() method called after controller action.      * in our template controller override method can      * make last minute modifications template before      * rendered.      */     public function after()      {         if ($this->auto_render) {              //set css files include             $styles = array(                 'style1', //the css file defaults site                 'jquery-library-css'             );               //set javascript files include             $scripts = array(                 'myscript1',                 'myscript2'             );               $admin_scripts = array(                 'jquery-admin-functions',             );             //now, merge information 1 can accessed             //by derived classes:             $this->template->styles = array_merge($this->template->user_styles, $user_styles);             $this->template->scripts = array_merge($this->template->user_scripts, $user_scripts);             $this->template->admin_scripts = array_merge($this->template->admin_scripts, $admin_scripts);         }          //bind site_name template view         $this->template->site_name = 'my site name';           //old way shown below:         view::set_global('site_name', 'my site name'); //set site name          //now has been set, use parent::after() finish setting values         //and start rendering         parent::after();     }  } 

so, how work? remember application.php class base controller class other controller classes derived from. by implementing type of binding base controller, every derived controller has access scripts, styles, etc. available. and, result every associated view called controller has access variables.

so, access variables in view:

example, template php file: /application/views/template.php

if it's defined (using php short tags - do not use short tags in production code!):

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd> <html> <head>     <meta charset='utf-8'/>     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <?php /**  * link css files stored in `static` folder project root.  * vary depending on how have files saved.  */ foreach($user_styles $style) : ?>     <link rel="stylesheet" href="<?php echo url::base() . 'static/css/' . $style ?>.css" type="text/css"/> <?php endforeach; ?>     <?php //create , set dynamic page title - facebook ?>     <title><?php echo $site_name; if(!empty($title)) echo ' - ' . $title; ?></title> </head> <body>  <!-- fill in body html, php - whatever want -->  <?php /**  * now, load scripts:  * according yahoo, better site performance, scripts should loaded after body has been loaded  */  foreach($user_scripts $script) : ?>     <script src="<?php echo url::base() . 'static/js/' . $script; ?>.js" type="text/javascript"></script> <?php endforeach; ?> </body> </html> 

there two takeaway points of this:

one: if want global, or available controllers (and subsequent views), define them , bind them in base application controller class.

two: result, this functionality gives tremendous leverage , power in if have derived classes, can them implement same type of binding particular controller class making available subsequent derived controller classes. way, if have 2 classes should not have access files , associated functionality, e.g. admin javascript file loads posts user, kind of implementation can make life much, much, easier.

and, third hidden option give kohana php, can use regular vanilla php / html in associated view if can't figure out immediately. although, i dissuade doing in production code.

whichever way, hope can assist you.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -