CodeIgniter L2 helper & libraries & form validation
-
Upload
mohammad-tahsin-al-shalabi -
Category
Technology
-
view
139 -
download
3
Transcript of CodeIgniter L2 helper & libraries & form validation
Codeigniter Framework
2.Helper & Libraries & Form Validation
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Agenda
• Form helper.
• Form validation.
• URI Class.
• Libraries.
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Form helper
• form_open()
• form_input()
• form_password()
• form_textarea()
• form_dropdown()
• form_upload()
• form_hidden()
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Form helper
• form_multiselect()
• form_checkbox()
• form_radio()
• form_submit()
• form_reset()
• form_close()
• set_value()
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Form helper Vs HTML
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
<form action="<?php echo site_url('controller/method'); ?>" method="post">
vrs
<?php echo form_open('controller/method');
Form validation
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
class Form extends CI_Controller {
function index()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
Form validation
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
class Form extends CI_Controller {
function index()
{
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}
}
URI Class
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• The URI Class provides functions that help
you retrieve information from your URI
strings
• Note: This class is initialized automatically
by the system so there is no need to do it
manually..
URI Class
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• $this->uri->segment(n)
• example:http://example.com/index.php/news/local/metro/crime_is_up
• The segment numbers would be this:
1. news
2. local
3. metro
4. crime_is_up
URI Class
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• $this->uri->uri_to_assoc(n)
• example:index.php/user/search/name/joe/location/UK/gender/male
• [array]
(
'name' => 'joe'
'location' => 'UK'
'gender' => 'male'
)
URI Class
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• $this->uri->uri_string()Returns a string with the complete URI
• $this->uri->total_segments()Returns the total number of segments.
• $this->uri->segment_array()Returns an array containing the URI segments
Libraries
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• File names must be capitalized. For example: Myclass.php
• Class declarations must be capitalized. For
example: class Myclass
• Class names and file names must match.
•Class declarations must be capitalized. For example: class Myclass
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Someclass {
public function some_function()
{
}
}
/* End of file Someclass.php */
Libraries
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Loading the library & Calling some function.
•Class declarations must be capitalized. For example: class Myclass
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class mycontroller{
public function my_function()
{
$this->load->library('someclass');
$this->someclass->some_function();
}
}
/* End of file Someclass.php */