Skip to content

Instantly share code, notes, and snippets.

@gopalkumar315
Created June 4, 2016 16:06
Show Gist options
  • Save gopalkumar315/c43eac4a9f5192aac5c1f299817d6c35 to your computer and use it in GitHub Desktop.
Save gopalkumar315/c43eac4a9f5192aac5c1f299817d6c35 to your computer and use it in GitHub Desktop.
Codeigniter - Widget Library (Backup)
class User_login extends Widget
{
function run($visible = FALSE) {
if ($post = $this->input->post('loginform')) {
if ($post['username'] == 'admin') {
$query = $this->db->query("SELECT uid FROM user WHERE username='admin'");
$result = $query->row();
set_cookie('ci_user', $result->uid, 86500);
redirect();
}
}
if ($visible) $this->render('user_login');
}
}
<div class="widget">
<div class="header">Login</div>
<div class="content">
<form action="" method="post">
<div class="row">
<label for="loginform_username">Username</label><br/>
<input name="loginform[username]" id="loginform_username" type="text" value="" /></div>
<div class="row">
<label for="loginform_password">Password</label><br/>
<input name="loginform[password]" id="loginform_password" type="password" value="" /></div>
<div class="row">
<input type="hidden" value="0" name="loginform[rememberme]" /><input name="loginform[rememberme]" id="loginform_rememberme" value="1" type="checkbox" /><label for="loginform_rememberme">Remember me next time</label></div>
<div class="row">
<input type="submit" value="Login" /></div>
</form>
</div></div>
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Widget Library
* http://codeigniter.com/forums/viewthread/109584/
*
* @version: 0.21
* $copyright Copyright (c) Wiredesignz 2009-09-07
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
class Widget
{
public $module_path;
function run($file) {
$args = func_get_args();
$module = '';
/* is module in filename? */
if (($pos = strrpos($file, '/')) !== FALSE) {
$module = substr($file, 0, $pos);
$file = substr($file, $pos + 1);
}
list($path, $file) = Modules::find($file, $module, 'widgets/');
if ($path === FALSE) {
$path = APPPATH.'widgets/';
}
Modules::load_file($file, $path);
$file = ucfirst($file);
$widget = new $file();
$widget->module_path = $path;
return call_user_func_array(array($widget, 'run'), array_slice($args, 1));
}
function render($view, $data = array()) {
extract($data);
include $this->module_path.'views/'.$view.EXT;
}
function load($object) {
$this->$object = load_class(ucfirst($object));
}
function __get($var) {
global $CI;
return $CI->$var;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment