Created
November 24, 2011 04:38
-
-
Save tediscript/1390628 to your computer and use it in GitHub Desktop.
CodeIgniter Widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!defined('BASEPATH')) | |
exit('No direct script access allowed'); | |
class widgetlib { | |
function __construct() { | |
include(APPPATH . '/third_party/Widget.php'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.