Friday, 10 July 2015

Changed the base URL but old base url seems to be cached somewhere in Magento

Make a test.php file and upload in your server and run it. so clean your store and remove unwanted file and folder like var/cache... 

## Function to set file permissions to 0644 and folder permissions to 0755

function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){ $d = new RecursiveDirectoryIterator( $dir ); foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){ if( $path->isDir() ) chmod( $path, $dirModes ); else if( is_file( $path ) ) chmod( $path, $fileModes ); }}
## Function to clean out the contents of specified directory
function cleandir($dir) { if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && is_file($dir.'/'.$file)) { if (unlink($dir.'/'.$file)) { } else { echo $dir . '/' . $file . ' (file) NOT deleted!<br />'; } } else if ($file != '.' && $file != '..' && is_dir($dir.'/'.$file)) { cleandir($dir.'/'.$file); if (rmdir($dir.'/'.$file)) { } else { echo $dir . '/' . $file . ' (directory) NOT deleted!<br />'; } } } closedir($handle); } } function isDirEmpty($dir){ return (($files = @scandir($dir)) && count($files) <= 2);} echo "----------------------- CLEANUP START -------------------------<br/>";$start = (float) array_sum(explode(' ',microtime()));echo "<br/>*************** SETTING PERMISSIONS ***************<br/>";echo "Setting all folder permissions to 755<br/>";echo "Setting all file permissions to 644<br/>";AllDirChmod( "." );echo "Setting pear permissions to 550<br/>";chmod("pear", 550); echo "<br/>****************** CLEARING CACHE ******************<br/>"; if (file_exists("var/cache")) { echo "Clearing var/cache<br/>"; cleandir("var/cache");} if (file_exists("var/session")) { echo "Clearing var/session<br/>"; cleandir("var/session");} if (file_exists("var/minifycache")) { echo "Clearing var/minifycache<br/>"; cleandir("var/minifycache");} if (file_exists("downloader/pearlib/cache")) { echo "Clearing downloader/pearlib/cache<br/>"; cleandir("downloader/pearlib/cache");} if (file_exists("downloader/pearlib/download")) { echo "Clearing downloader/pearlib/download<br/>"; cleandir("downloader/pearlib/download");} if (file_exists("downloader/pearlib/pear.ini")) { echo "Removing downloader/pearlib/pear.ini<br/>"; unlink ("downloader/pearlib/pear.ini");} echo "<br/>************** CHECKING FOR EXTENSIONS ***********<br/>";If (!isDirEmpty("app/code/local/")) { echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder<br/>";}If (!isDirEmpty("app/code/community/")) { echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder<br/>";}$end = (float) array_sum(explode(' ',microtime()));echo "<br/>------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------<br/>";?>

Wednesday, 1 July 2015

How to get number of rows affected, While executing mysql query PHP

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');
/* this should return the correct numbers of deleted records */
mysql_query('DELETE FROM mytable WHERE id < 10');
printf("Records deleted: %d\n", mysql_affected_rows());
/* with a where clause that is never true, it should return 0 */
mysql_query('DELETE FROM mytable WHERE 0');
printf("Records deleted: %d\n", mysql_affected_rows());
?>

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));
}