Codeigniter

Controller

public function __construct(){
    
     parent::__construct();
   
     $this->load->model('admin_model');
     $this->class = strtolower(__CLASS__);
     $this->page_limit = 20;                        // Setting the number of records per page for Pagination
     $this->load->helper(array('url','form'));
     $this->load->library(array('form_validation','session','parser','pagination'));
   
      $this->load->library("excel");
   
   }


Model:

class Agent_model extends CI_Model{
  
       public function __construct(){
        
         $this->load->database();
       }
}


$data['content']=$this->parser->parse('agentpanel/dashboard',$data,TRUE); //Parsing the index
           $this->parser->parse('template',$data);

in template

{content}

Pagination

$config=array('first_link'=>'First','first_tag_open'=>'<li>','first_tag_close'=>'</li>','last_link'=>'Last','last_tag_open'=>'<li class="last">','last_tag_close'=>'</li>','next_link'=>'&gt;','next_tag_open'=>'<li>','next_tag_close'=>'</li>','prev_link'=>'&lt;','prev_tag_open'=>'<li>','prev_tag_close'=>'</li>','first_link'=>'First','cur_tag_open'=>'<li><a class="active">','cur_tag_close'=>'</a></li>','num_tag_open'=>'<li>','num_tag_close'=>'</li>','base_url'=> base_url('controller/method/'),'per_page' => $this->page_limit,'total_rows'=>10);

        $this->pagination->initialize($config);

        $this->pagination->create_links() // in view 

File Upload

$Pre_Name=substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"),0,5);
$Image_Name=$Pre_Name.'_'.$_FILES['image']['name'];
        $Image_Temp=$_FILES['image']['tmp_name'];
        $Image_Path='addon_images/'.$Image_Name;
        move_uploaded_file($Image_Temp,$Image_Path);

unlink('addon_images/'.$Image_Name);


HTACCESS 

RewriteEngine on
RewriteBase /codeigniter/
RewriteCond $1 !^(index\.php|airline_images|images|robots\.txt|sitemap\.xml)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^(.*)$ /
codeigniter/index.php/$1 [L]


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]

RewriteCond $1 !^(index\.php|airline_images|images|robots\.txt|sitemap\.xml)  
#RewriteRule ^(.*)$ /DirectTraveller/index.php/$1 [L]
RewriteRule ^(.*)$ /index.php/$1 [L]


File Upload by using do_upload library 

$config['upload_path'] = './temp_upload_images/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $config['file_name']  = 'newname';
        $config['overwrite']  = false;

        $this->load->library('upload', $config);
        $this->upload->initialize($config);

        if ( ! $this->upload->do_upload('image[]'))
        {
             $error = array('error' => $this->upload->display_errors());print_r($error);exit;

        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
print_r($data);exit;
           
        }
 

No comments:

Post a Comment