Skip to content

Instantly share code, notes, and snippets.

@tediscript
Created November 24, 2011 04:38
Show Gist options
  • Save tediscript/1390628 to your computer and use it in GitHub Desktop.
Save tediscript/1390628 to your computer and use it in GitHub Desktop.
CodeIgniter Widget
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Widget {
static $a = array();
function Widget() {
$this->_assign_libraries();
}
function run($name, $data = array()) {
self::$a = $data;
$args = func_get_args();
require_once APPPATH . 'widgets/' . $name . EXT;
$arrname = explode('/', $name);
$name = $arrname[sizeof($arrname) - 1];
$name = ucfirst($name);
$widget = new $name();
return call_user_func_array(array(&$widget, 'run'), array_slice($args, 1));
}
function render($view, $data = array()) {
$ci = & get_instance();
$defaultThemes = $ci->config->item('themes');
$data = array_merge($data, self::$a);
extract($data);
include APPPATH . 'views/themes/' . $defaultThemes . '/widgets/' . $view . EXT;
}
function theme($view, $data = array(), $ret = false) {
$ci = & get_instance();
$defaultThemes = $ci->config->item('themes');
$view = 'themes/' . $defaultThemes . '/widgets/' . $view;
$ci->load->view($view, $data, $ret);
}
function view($view, $data = array(), $ret = false) {
$ci = & get_instance();
return $ci->load->view($view, $data, $ret);
}
function load($object) {
$this->$object = & load_class(ucfirst($object));
}
function _assign_libraries() {
$ci = & get_instance();
foreach (get_object_vars($ci) as $key => $object) {
$this->$key = & $ci->$key;
}
}
}
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class widgetlib {
function __construct() {
include(APPPATH . '/third_party/Widget.php');
}
}
Copy link

ghost commented Jul 30, 2013

Hello, i am a newbie to codeigniter. I have integrated this code in my website but I don't know how to run the widget. Can you please explain how to run widget in codeigniter? Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment