Get Max Id of A Table : Function / Method

Get Max Id of A Table in Codeigniter : Function / Method   <?php // Function for get max id public function get_max_id($table) { $this->db->select_max(‘id’); $query = $this->db->get($table); $res = $query->row(); return $res->id; } ?>  

Codeigniter Form Elements

Input Element   <?php echo form_input([‘name’ =>’city’, ‘id’ => ‘city’, ‘class’ => ‘form-control’, ‘placeholder’ => ‘City’, ‘value’ => set_value(‘city’)]);?>  

Image uploading code in Codeigniter

  <?php if($this->input->post(‘submit’)) { if(!empty($_FILES[“product_image”][‘name’])) { $config = array( ‘upload_path’ => “./uploads/products/”, ‘allowed_types’ => “jpg|jpeg|png|gif”, ‘overwrite’ => TRUE, ‘max_size’ => “2048000”, // Can be set to particular file size , here it is 2 MB(2048 Kb) //’max_height’ => “768”, //’max_width’ => “1024”, ‘file_name’ => time().’-‘.$_FILES[“product_image”][‘name’] ); $uploaderror = ”; $this->load->library(‘upload’, $config); if($this->upload->do_upload(‘product_image’)) { $uploadData = […]

Model code for handle login in Codeigniter

  <?php class Loginmodel extends CI_Model { public function login_valid( $email, $password ) { $q = $this->db->where([’email’ => $email, ‘password’ => $password]) ->get(‘users’); if( $q->num_rows() ) { //return $q->row()->id; return $q->row(); } else { return FALSE; } } } ?>  

Code for handle login controller

  class Login extends MY_Controller { /** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * – or – * http://example.com/index.php/welcome/index * – or – * Since this controller is set as the default controller in * config/routes.php, it’s displayed at http://example.com/ * * So any other public […]

Creating a form in Codeigniter

Creating a form in Codeigniter, This program will create a form in codeigniter.   <?php echo form_open(current_url(), [‘method’ => ‘post’]);?> <div class=”form-group has-feedback”> <?php echo form_input([‘name’ => ‘username’, ‘type’ => ’email’, ‘class’ => ‘form-control’, ‘placeholder’ => ‘Enter email’, ‘value’ => set_value(‘username’)]);?> <span class=”glyphicon glyphicon-envelope form-control-feedback”></span> <?php echo form_error(‘username’);?> </div> <div class=”form-group has-feedback”> <?php echo form_password([‘name’ […]

Integrating HTML template into codeigniter

First create a folder “assets” in main folder for html template’s CSS, JS and Images Paste all css and js files inside assets folder Goto:- application>views> (create a test.php file and paste html code) Open:- Application>config>autoload.php (Pass ‘url’ in helper array) Open:- Application>config>autoload.php (Pass ‘database’,’session’ in libraries array) Write the following code in your test […]

Starting With Codeiginiter

Download and extract codeigniter zip file where you want to start the project. Create an .htaccess file with following content (for removing index.php) RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] Goto:-  application>core> (create a controller for having common mehods) – Optional Create and test a function for testing that controller […]