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.

Programatically show a webform block in Drupal 7

Put this code in any tpl file where you would like to show.

$block = module_invoke('webform', 'block_view', 'client-block-26');
print render($block['content']);

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