Friday 26 June 2015

CodeIgniter Remove index.php from URL

change in .htaccess file and try it

RewriteEngine OnRewriteBase /project/RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Pagination in CodeIgniter

Controller:
------------------------
public function index() {
        $count = $this->dcategory->Count_drugcategories();
        $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
        $this->load->library('pagination');
        $config['base_url'] = base_url('drug_categories');
        $config['use_page_numbers'] = TRUE;
        $config['total_rows'] = $count;
        $config['per_page'] = 10;
        $config["uri_segment"] = 2;
        $this->pagination->initialize($config);
        $limit = $config['per_page'];
        $start = ($page  == 0) ? 0 : ($page * $config['per_page']) - $config['per_page'];
        $data['query'] = $this->dcategory->Getlist_drugcategories($start,$limit);      
        $seo['title'] = 'Drug Categories List | ekimed';
        $data['links'] = $this->pagination->create_links();
        $this->load->view('layout/header',$seo);
        $this->load->view('drug_categories/listdrugcategories',$data);
        $this->load->view('layout/footer');
    }

Model:
----------------------
function Getlist_drugcategories($limit=0,$start=0){
        $this->db->select('*');
        if($limit>0 && $start>=0) {
            $this->db->limit($limit,$start);
        } else {
            $this->db->limit(10);
        }
        $query = $this->db->get($this->drugs_category);
        if($query->num_rows() > 0){
            return $query->result();
        } 
        return FALSE;
    }

Views:
-----------
<?php echo $links; ?>

Inserting multiple rows mysql in codeigniter

if your php version>=5.4 it should work.
You may try this

if ($_POST) { $row_ids=$this->input->post('id'); $desc=$this->input->post('desc'); $spaces=$this->input->post('space'); $prices=$this->input->post('price'); $totals=$this->input->post('total'); $data = array(); for ($i = 0; $i < count($this->input->post('id')); $i++) { $data[$i] = array( 'row_id' => $row_ids[$i], 'desc' => $desc[$i], 'space' => $spaces[$i], 'price' => $prices[$i], 'total' => $totals[$i], 'code' => time() ); } $this->Home_model->create($data); }

Only variable references should be returned by reference - Codeigniter

Edit filename: core/Common.php, line number: 257

Before

return $_config[0] =& $config; 
 
After
 
$_config[0] =& $config;return $_config[0];  

How to called codeigniter helper function using JQuery AJAX?

You need to make a request via controller, then call that function through that controller, something like:
 
 
$("#id").change(function()
{       
 $.ajax({
     type: "POST",
     url: base_url + "controller_name/your_function", 
     data: {val: $("#your_val").val(),currency_id: $("#your_cur").val()},
     dataType: "JSON",  
     cache:false,
     success: 
          function(data){
            $("#your_elem").val(data.price);
      }
});
 
 
Then on your controller:

public function yourfunction()
{
   $data = $this->input->post();
   $price = format_price($data['val'],$data['currency_id']);
   echo json_encode(array('price' => $price));
}

PHP - CodeIgniter - Invalid argument supplied for foreach()

<?php if(is_array($result)): ?>
<?php foreach($result as $row):?>  
<h3><? echo $row->title; ?></h3>  
<p><? echo $row->text; ?></p>  
<?php endforeach;?>  
<?php endif; ?>

How to assign category on multiple products in Magento

  • In your backend, go to Catalog -> Categories -> Manage Categories.
  • Select the category you want to add products to.
  • Click "Category Products" Tab
  • Reset the Filter, select your products, Save Category