Tips for Magento site speed up

Tips for Magento site speed up Summary:

  • Enable all Magento caching layers.
  • Configure your web server to enable Connection Keep-Alive, enable mod_expire, gzip compression.
  • Enable MySQL Query caching.
  • Install APC or XCache to cache PHP opcode.
  • Install Memcache and configure Magento to store session and cache to memory.
  • Install third-party Full Page Cache Magento extension.
  • Install Varnish cache server for full page caching on system layer.

Remove WordPress logo from admin bar

Add this code to your functions.php file to remove the WordPress logo on admin bar.

<?php
function annointed_admin_bar_remove() {
 global $wp_admin_bar;

 /* Remove their stuff */
 $wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);
?>

Adding Conditional Stylesheets for Internet Explorer in Drupal

There are two ways of doing this – you can either use drupal_add_css() with the optional browser type parameter, or go the easier route and use the Conditional Styles module which allows you to add CSS files via your themes info file. First lets use drupal_add_css() with the browser type. You should use this in themename_preprocess_html() (which goes in your themes template.php file) such as this

<?php
function my_groovy_theme_preprocess_html(&$vars) {
drupal_add_css(drupal_get_path('theme''my_groovy_theme') . '/lte-ie-8.css', array(
'group' => CSS_THEME,
'browsers' => array(
'IE' => 'lte IE 8',
'!IE' => FALSE
),
'preprocess' => FALSE
));
}
?>

This code is targeting IE8 or less

There is a much easier way to declare conditional stylesheets in Drupal – use the Conditional Styles module. This module allows you to declare conditional CSS in your themes info file, just as easily as the very first examples in this article. Just install the module and you can do stuff like this in your themes info file:

stylesheets-conditional[lte IE 8][all][] = lte-ie-8.css

I hope this helps you get started with Drupal theming a bit easier

Symfony Slugify Slug

A slug is basically a URL-friendly string for identifying a post, page, user, etc..  It provides a better idea of what the content the URL points to and will actually be about.

There are 4 basic steps in Symfony slugging.  

Create a route for the slugged model in the routing.yml config file using the sfDoctrineRoute class and pass to your model’s show action

 

account_show_user:
  url: /member/:slug
  class: sfDoctrineRoute
  param: { module: account, action: show }
  options: { model: sfGuardUser, type: object }
  requirements:
    id: \d+
    sf_method: [get]


Add the Sluggable behavior to your model in schema.yml and define the field we want slugged.

sfGuardUser:
  actAs:
    Postable: ~
    Timestampable: ~
    Sluggable:
      unique: true
      fields: [username]
      canUpdate: true
  #...

Create a generic project class with the slugify method or behavior (replacing spaces with hyphens etc.)

class Slugz
{
  static public function slugify($text)
  {
    // replace all non letters or digits by -
    $text = preg_replace('/\W+/', '-', $text);

    // trim and lowercase
    $text = strtolower(trim($text, '-'));
 
    return $text;
  }
}

Create the show action within the model’s action file. Make sure to reference the route object that the routing.yml config file has internally created.

public function executeShow(sfWebRequest $request)
  {
    $this->account = $this->getRoute()->getObject();
    $this->forward404Unless($this->account);
  }

For more

Unable to write cache file” problem in Symfony 2

One common issue in Symfony 2 projects is that the “app/cache” and “app/logs” directories must be writable both by the web server and the command line user. On a UNIX system, if your web server user is different from your command line user, you can run the following commands just once in your project to ensure that permissions will be setup properly. 

Simply type the following command:

 

sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs

Integration of CKEditor in Yii Framework

1. Download CKEditor extension here

2. Put it in your app/protected/extensions/

3. In your form, write this code

<?php   $this->widget(‘application.extensions.ckeditor.CKEditor’, array(                          ‘model’=>$model,                          ‘attribute’=>’filed name’,                          ‘language’=>’english’,                          ‘editorTemplate’=>’full’,               ));?>

Export Gridview Filtered Result To Excel in Yii framework

public function actionAdmin() {
                $model=new Customer('search');
                $model->unsetAttributes();  // clear any default values
                if(isset($_GET['Customer']))
                        $model->attributes=$_GET['Customer'];
                
                Yii::app()->user->setState('exportModel',$model); //this can be any other storage

                $this->render('admin',array(
                        'model'=>$model,
                ));
        }

public function actionExportToFile() {
                //echo 'test';
                header('Content-type: text/csv');
                header('Content-Disposition: attachment; filename="report-customers-' . date('YmdHi') .'.csv"');

                $model=new Customer('search');
                $model->unsetAttributes();  // clear any default values
                
                if(Yii::app()->user->getState('exportModel'))
                      $model=Yii::app()->user->getState('exportModel');

                $dataProvider = $model->search(false);
                
                // csv header
                echo    Customer::model()->getAttributeLabel("Id").",". 
                                Customer::model()->getAttributeLabel("Country_Id").",". 
                                Customer::model()->getAttributeLabel("Gender_Id").",".
                                Customer::model()->getAttributeLabel("First_Name").",".
                                Customer::model()->getAttributeLabel("Last_Name").
                                " \r\n";
                // csv data
                foreach ($dataProvider->getData() as $data) {
                        echo "$data->Id, $data->Country_Id, $data->Gender_Id, $data->First_Name, $data->Last_Name \r\n";
                }
                
                exit; 
        }