Skip to content

Instantly share code, notes, and snippets.

@andyhawthorne
andyhawthorne / testing.php
Created October 17, 2012 13:32
CI Drivers
<?php
class Testing extends CI_Driver_Library
{
protected $valid_drivers = array();
private $ci;
public function __construct()
{
//get the super object
$this->ci =& get_instance();
<?php
public function admin_home()
{
check_login();
$this->load->view('admin_home_view');
}
?>
<?php
class Admin_model extends CI_Model
{
function __construct()
{
parent:: __construct();
}
public function verify_user($email, $password)
<?php
function check_login()
{
$CI =& get_instance();
$user = $CI->session->userdata('username');
if(!isset($user))
{
redirect('admin');
}
<?php
public function index()
{
$user = $this->session->userdata('username');
if(isset($user))
{
redirect('admin/admin_home');
}
$this->form_validation->set_rules('email_address', 'Email Address', 'valid_email|required');
<?php
class Admin extends MX_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('admin');
$this->load->library('form_validation');
@andyhawthorne
andyhawthorne / searchterm_handler.php
Last active October 10, 2015 19:28
Search term handler method
<?php
public function searchterm_handler($searchterm)
{
if($searchterm)
{
$this->session->set_userdata('searchterm', $searchterm);
return $searchterm;
}
elseif($this->session->userdata('searchterm'))
{
@andyhawthorne
andyhawthorne / search_view.php
Created September 17, 2012 19:28
search form
<form action ="<?=base_url()?>welcome/search" method="post" id="searchform">
Search the database:&nbsp;
<input type="text" name="searchterm" id="searchterm" value="<?=$searchterm?>" />&nbsp;
<input type="submit" value="Search >>" id="submit" />
</form>
@andyhawthorne
andyhawthorne / search.php
Last active October 10, 2015 19:27
search method
<?php
public function search($searchterm,$limit)
{
$sql = "SELECT * FROM Country
WHERE Continent LIKE '%" . $searchterm . "%' LIMIT " .$limit . ",20";
$q = $this->db->query($sql);
if($q->num_rows() > 0)
{
foreach($q->result() as $row)
{
@andyhawthorne
andyhawthorne / search_model.php
Last active October 10, 2015 19:27
method for counting search results
<?php
public function search_record_count($searchterm)
{
$sql = "SELECT COUNT(*) As cnt FROM Country
WHERE Continent LIKE '%" . $searchterm . "%'";
$q = $this->db->query($sql);
$row = $q->row();
return $row->cnt;
}