Guest User

Untitled

a guest
Oct 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Content extends Admin_Controller {
  4.  
  5.   public function __construct()
  6.   {
  7.       parent::__construct();
  8.  
  9.       Template::set('toolbar_title', 'ToDo List');
  10.  
  11.       $this->load->model('Todo_model', 'todo_model', true);
  12.   }
  13.  
  14.   public function index()
  15.     {
  16.       if ($this->input->post('submit'))
  17.       {
  18.         $this->form_validation->set_rules('description', 'Description', 'required|callback_description_check|trim|strip_tags|max_length[10]|xss_clean');
  19.        
  20.         if ($this->form_validation->run() !== FALSE)
  21.         {
  22.             $this->todo_model->insert($this->input->post());
  23.             Template::set_message('New ToDo item successfully created', 'success');
  24.         }
  25.         else
  26.         {
  27.           Template::set_message('Error creating new ToDo item.', 'error');
  28.         }
  29.       }
  30.       Template::set('items', $this->todo_model->order_by('todo_id', 'desc')->find_all_by('deleted', 0));
  31.      
  32.       Template::render();
  33.     }
  34.  
  35.   public function delete()
  36.   {
  37.       $id = $this->uri->segment(5);
  38.  
  39.       $this->todo_model->delete($id);
  40.  
  41.       echo 'true';
  42.       die();
  43.   }
  44.  
  45.  
  46.   /**
  47.    * validation callback
  48.    */
  49.   function description_check($str) {
  50.  
  51.     if ($str == 'test')
  52.     {
  53.       $this->form_validation->set_message('description_check', 'The %s field can not be the word "test"');
  54.       return FALSE;
  55.     }
  56.     else
  57.     {
  58.       return TRUE;
  59.     }
  60.   }
  61.  
  62. }
Add Comment
Please, Sign In to add comment