CodeIgniter Class Reference
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

CodeIgniter Class Reference

on

  • 1,659 views

Useful class references in CodeIgniter

Useful class references in CodeIgniter

Statistics

Views

Total Views
1,659
Views on SlideShare
1,659
Embed Views
0

Actions

Likes
2
Downloads
53
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • $this->db->like(‘title’,’match’,’after’);$this->db->like(‘title’,’match’,’before’);$this->db->like(‘title’,’match’,’both’);$this->db->like(‘title’,’match’,’none’);
  • $this->db->order_by('title desc, name asc');
  • Max sizes in KB

CodeIgniter Class Reference Presentation Transcript

  • 1. CodeIgniter Class Reference Jamshid Hashimi Trainer, Cresco Solution http://www.jamshidhashimi.com jamshid@netlinks.af @jamshidhashimi ajamshidhashimi Afghanistan Workforce Development Program
  • 2. Agenda • Database Class • Calendar Class • Config Class • Email Class • File Uploading Class • Form Validation Class
  • 3. Database Class • CodeIgniter comes with a full-featured and very fast abstracted database class that supports both traditional structures and Active Record patterns. The database functions offer clear, simple syntax. • Usage Examples $this->load->database(); $DB1 = $this->load->database('group_one', TRUE); $DB2 = $this->load->database('group_two', TRUE);
  • 4. Database Class • Configuration $active_group = 'default'; $active_record = TRUE; $db['default']['hostname'] = 'localhost'; $db['default']['username'] = 'root'; $db['default']['password'] = ''; $db['default']['database'] = 'sakila'; $db['default']['dbdriver'] = 'mysql'; $db['default']['dbprefix'] = ''; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ''; $db['default']['char_set'] = 'utf8'; $db['default']['dbcollat'] = 'utf8_general_ci'; $db['default']['swap_pre'] = ''; $db['default']['autoinit'] = TRUE; $db['default']['stricton'] = FALSE;
  • 5. Database Class • Standard Query • Result $query = $this->db->query('SELECT name, title, email FROM my_table'); $query->result() //Object $query->result_array() //Array
  • 6. Database Class • Testing Result • Single Result if ($query->num_rows() > 0) $query = $this->db->query('SELECT name FROM my_table LIMIT 1'); $row1 = $query->row(); $row2 = $query->row_array(); echo $row1->name; echo $row2[‘name’];
  • 7. Database Class • Affected Rows $sql = "INSERT INTO mytable (title, name) VALUES (".$this->db->escape($title).", ".$this- >db->escape($name).")"; $this->db->query($sql); echo $this->db->affected_rows();
  • 8. Database Class • Query Helper Functions $this->db->insert_id(); $this->db->affected_rows(); $this->db->count_all(); $this->db->platform(); $this->db->version(); $this->db->last_query();
  • 9. Database Class • Active Record – Selecting Data • Selecting Data – LIMIT $query = $this->db->get('mytable'); // Produces: SELECT * FROM mytable $query = $this->db->get('mytable', 10, 20); // Produces: SELECT * FROM mytable LIMIT 20, 10
  • 10. Database Class • Selecting Data – Result • get_where() $query = $this->db->get('mytable'); foreach ($query->result() as $row) { echo $row->title; } $query = $this->db->get_where('mytable', array('id' => $id), $limit, $offset);
  • 11. Database Class • $this->db->select(); • $this->db->select_max(); • $this->db->select_min(); • $this->db->select_avg(); • $this->db->select_sum(); • $this->db->from(); • $this->db->where(); • $this->db->join();
  • 12. Database Class • $this->db->or_where(); • $this->db->where_in(); • $this->db->or_where_in(); • $this->db->where_not_in(); • $this->db->or_where_not_in(); • $this->db->like(); • $this->db->or_like(); • $this->db->not_like(); • $this->db->or_not_like();
  • 13. Database Class • $this->db->group_by(); • $this->db->distinct(); • $this->db->having(); • $this->db->or_having(); • $this->db->order_by();
  • 14. Database Class • Inserting Data – $this->db->insert(); $data = array( 'title' => 'My title' , 'name' => 'My Name' , 'date' => 'My date' ); $this->db->insert('mytable', $data); // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
  • 15. Database Class • Inserting Data – $this->db->insert_batch(); $data = array( array( 'title' => 'My title' , 'name' => 'My Name' , 'date' => 'My date' ), array( 'title' => 'Another title' , 'name' => 'Another Name' , 'date' => 'Another date' ) ); $this->db->insert_batch('mytable', $data);
  • 16. Database Class • Updating Data – $this->db->update(); $data = array( 'title' => $title, 'name' => $name, 'date' => $date ); $this->db->where('id', $id); $this->db->update('mytable', $data);
  • 17. Database Class • Updating Data – $this->db->update_batch(); $data = array( array( 'title' => 'My title' , 'name' => 'My Name 2' , 'date' => 'My date 2' ), array( 'title' => 'Another title' , 'name' => 'Another Name 2' , 'date' => 'Another date 2' ) ); $this->db->update_batch('mytable', $data, 'title');
  • 18. Database Class • Deleting Data – $this->db->delete(); – $this->db->truncate(); • Method Chaining $this->db->where('id', $id); $this->db->delete('mytable');
  • 19. DEMO
  • 20. Calendar Class • The Calendar class enables you to dynamically create calendars. Your calendars can be formatted through the use of a calendar template, allowing 100% control over every aspect of its design. In addition, you can pass data to your calendar cells. echo $this->calendar->generate(); echo $this->calendar->generate(2006, 6);
  • 21. DEMO
  • 22. Config Class • The Config class provides a means to retrieve configuration preferences. $this->config->item('item name'); $this->config->set_item('item_name', 'item_value');
  • 23. DEMO
  • 24. Email Class • Multiple Protocols: Mail, Sendmail, and SMTP • Multiple recipients • CC and BCCs • HTML or Plaintext email • Attachments • Word wrapping • Priorities • BCC Batch Mode, enabling large email lists to be broken into small BCC batches. • Email Debugging tools
  • 25. Email Class
  • 26. Email Class $this->load->library('email'); $this->email->from('your@example.com', 'Your Name'); $this->email->to('someone@example.com'); $this->email->cc('another@another-example.com'); $this->email->bcc('them@their-example.com'); $this->email->subject('Email Test'); $this->email->message('Testing the email class.'); $this->email->send(); echo $this->email->print_debugger();
  • 27. Email Class • Send email with Gmail $this->load->library('email'); $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => 'youremail@gmail.com', 'smtp_pass' => 'yourpassword', );
  • 28. Email Class • Initialize Configuration $config['protocol'] = 'sendmail'; $config['mailpath'] = '/usr/sbin/sendmail'; $config['charset'] = 'iso-8859-1'; $config['wordwrap'] = TRUE; $this->email->initialize($config);
  • 29. Email Class • Attachments $this->email->attach('/path/to/photo1.jpg'); $this->email->attach('/path/to/photo2.jpg'); $this->email->attach('/path/to/photo3.jpg'); $this->email->send();
  • 30. File Upload Class • CodeIgniter's File Uploading Class permits files to be uploaded. You can set various preferences, restricting the type and size of the files. $this->upload->do_upload(); $this->upload->display_errors(); $this->upload->data();
  • 31. File Upload Class • Initializing Configurations $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config);
  • 32. DEMO
  • 33. Form Validation Class • CodeIgniter provides a comprehensive form validation and data prepping class that helps minimize the amount of code you'll write. <?php echo validation_errors(); ?> $this->form_validation->run()
  • 34. Form Validation Class
  • 35. DEMO
  • 36. Assignments
  • 37. QUESTIONS?