Skip to content

Instantly share code, notes, and snippets.

@arunoda

arunoda/css.php Secret

Created June 21, 2012 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arunoda/ac1706be629328092fab to your computer and use it in GitHub Desktop.
Save arunoda/ac1706be629328092fab to your computer and use it in GitHub Desktop.
Codeigniter - Creating a custom library
<?php
class Css {
var $files = array();
public function add($file) {
$this->files[] = $file;
}
public function generate() {
$cssString = "";
$CI = &get_instance();
$CI->load->helper('html');
foreach($this->files as $file) {
$cssString .= link_tag('css/' . $file) . "\n";
}
return $cssString;
}
}
<?php
class Hello extends MY_Controller {
public function index() {
$this->load->library('css');
$this->css->add('main.css');
$this->css->add('print.css');
echo $this->css->generate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment