Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
/ mz-codeigniter-crud Public archive

crud system for codeigniter , ajax delete and insert + auto search , sort , pagination ....

License

Notifications You must be signed in to change notification settings

Hretic/mz-codeigniter-crud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mz-codeigniter-crud

crud system for codeigniter , ajax delete and insert + list + auto search , sort , pagination ....

Requirements

  1. PHP 5.2 or greater
  2. CodeIgniter

Installation

copy the files in the root of your codeigniter application

List

list set of data from your database :

$config['labels'] = array( 'username'=>'Username' , 'email'=>' Email' );
$this->mz_crud->set_config($config);
$dataTable = $this->mz_crud->list_('users');

##Insert

$config['labels']  = array( 'username'=>'Alias' , 'email'=>'Email' , 'about_me'=> 'About Me' );
$config['ignor']  = array('id');
$config['check_duplicate']  = array( 'username' , 'email' );
$config['redirect']  = base_url().'index/crudList/';
$config['inp_type']  = array('username'=>'text' , 'about_me'=>'rich_textarea');

$this->mz_crud->set_config($config);
$insertTable = $this->mz_crud->add('users');

##Edit

$config['labels']  = array( 'username'=>'Alias' , 'email'=>'Email' , 'about_me'=> 'About Me' );
$config['ignor']  = array('id');
$config['check_duplicate']  = array( 'username' , 'email' );
$config['redirect']  = base_url().'index/crudList/';
$config['inp_type']  = array('username'=>'text' , 'about_me'=>'rich_textarea');

$this->mz_crud->set_config($config);
$insertTable = $this->mz_crud->edit( $id , 'users');

*see the sample code for more information

##Preferences

The preferences described below .

Note that not all preferences are availabel for every function.

Preference Default Value value Description Availability
labels database column label array of 'column'=>'label' pairs Sets the label for each database column in the view all
ignor None array of columns Sets column that should be ignored in the operation all
redirect current_url() string Sets the redirect URL after operation (edit
, insert )
add , edit
edit_url current_url() string Sets the Url to Edit function list_
fail_url current_url() string Sets the redirect URL after operation fails add , edit
inp_type type="text" array of 'column'=>'input type' pairs Sets the Html input type for each column. all
options empty array 2d array of 'column'=>array('option label'=>'option value') Sets the selectable options for input_type of (select , checkbox , radio ) all
check_duplicate None array of columns checks the database for duplicate before insert or edit all
md_options None array( 'add' , 'edit' , 'delete') Sets the moderating options for a list . list_
id_fild id string sets the id colum in database edit
per_page 0 int sets the per page option for pagination ( 0 == no pagination ) list_
search empty array array of columns sets the searchable colums and adds a search option to the list list_
sort empty array array of columns sets the sortable colums and adds a sort option to the list list_
documentready ampty array array javascript commands to be run on document ready all
lang array('file'=>'crud' , 'folder'=>'crud') array sets the address for language file all

##sample code

lets say we have a table called "users" users : id , username , email , recive_newsletter , profile

class index extends CI_Controller { 

	function crudList(){ 

		$this->load->library('mz_crud');

		$config['ignor']  = array('id' , 'recive_newsletter' , 'profile' );
		$config['check_duplicate']  = array( 'username' , 'email');
		$config['edit_url']    = base_url().'index/crudEdit/';
		$config['md_options']  = array( 'add' , 'edit' , 'delete');
		$config['labels']    = array( 'username'=>'UserName' , 'email'=>'Email);
		$config['per_page']  = 2;
		$config['search']    = array( 'username' , 'email');
		$config['sort']      = array( 'username');

		$this->mz_crud->set_config($config);
		echo $this->mz_crud->list_('users');

	}


	function crudInsert(){

		$this->load->library('mz_crud');

		$config['labels']  = array('username'=>'UserName' , 'email'=>'Email' , 'recive_newsletter'=>'would you like to recive our newsletter' , 'profile'=>'Choose how you share information on your profile ?');
		$config['ignor']   = array('id');
		$config['check_duplicate']  = array( 'username' , 'email' );
		$config['redirect']  = base_url().'index/crudList/';
		$config['inp_type']  = array('newsletter'=>'select' , 'profile'=>'radio');
		$config['options']   = array('newsletter'=>array('Yes , i do'=>'1' , 'No , thanx '=>'0' ) ,
		'profile'=>array('i want a public profile '=>'public' , 'i want a private profile'=>'private' ));
		$config['documentready']  = array('alert("Please fill in all fields ");');

		$this->mz_crud->set_config($config);
		echo $this->mz_crud->add('users');

	}




	function crudEdit( $id = 0 ){

		$this->load->library('mz_crud');

		$config['labels']  = array('username'=>'UserName' , 'email'=>'Email' , 'recive_newsletter'=>'would you like to recive our newsletter' , 'profile'=>'Choose how you share information on your profile ?');
		$config['ignor']   = array('id');
		$config['check_duplicate']  = array( 'username' , 'email' );
		$config['redirect']  = base_url().'index/crudList/';
		$config['inp_type']  = array('newsletter'=>'select' , 'profile'=>'radio');
		$config['options']   = array('newsletter'=>array('Yes , i do'=>'1' , 'No , thanx '=>'0' ) ,
		'profile'=>array('i want a public profile '=>'public' , 'i want a private profile'=>'private' ));
		$config['documentready']  = array('alert("Please fill in all fields ");');

		$this->mz_crud->set_config($config);
		echo $this->mz_crud->edit( $id , 'users');

	}


}

About

crud system for codeigniter , ajax delete and insert + auto search , sort , pagination ....

Resources

License

Stars

Watchers

Forks

Packages

No packages published