RSS Feed

‘php’ Category

  1. Ode to PHP

    July 25, 2011 by admin

    There are only two kinds of languages: the ones people complain about and the ones nobody uses

    Bjarne Stroustrup


  2. The thing about theming Magento

    May 31, 2011 by admin

    Note to self – If you want to survive major version cms upgrades, always use theme inheritance and overwrite defaults of the default theme that comes with Magento. I wish I knew …
    See also – Designer’s guide to Magento


  3. The one thing you need to know about building CMS themes

    November 10, 2010 by admin

    Does it support intelligent body classes?
    It will make your theming life so much easier, it’s absolutely ridiculous …

    Read about the WordPress version and the benefits of using this concept for theming purposes here: http://codex.wordpress.org/Template_Tags/body_class

    WordPress (2.8+):

    <body <?php body_class(); ?>>

    Drupal (originally from Zen Theme, since Drupal 6 in core):

    <body class="<?php print $body_classes; ?>">

    Joomla:

    Not available by default, must be built manually in template. The Joomla 1.6 version of the default Milkyway template uses something remotely similar for color and background parameters and template width.

    Magento:

    <body <?php echo $this->getBodyClass()?'class="'.$this->getBodyClass().'"':'' ?>>

  4. Google Trends on Web Frameworks- interesting

    September 8, 2010 by admin

    Do I need to say more … ?

    Google Trends Chart Web Frameworks


  5. Symfony 2 Preview – It has never been so easy

    June 29, 2010 by admin

    The Symfony PHP Framework has, in the past, alienated a lot of developers solely because it was quite a hassle to setup on shared hosting or a local server environment.

    What’s new in Symfony 2.0?

    • Requires PHP5.3.2+
    • Doctrine 2 (Active Record is replaced by Entity Pattern, completely rewritten codebase for PHP5.3)
    • PHPUnit for testing, lime is out for good
    • Logging and caching with Zend Framework
    • Access to remote APIs (web services, feeds, etc.)
    • Support for Lucene indexes
    • PDf generation
    • Queueing
    • Cloud computing (storage, DBs, message queues)
    • Forms2, the new form framework
    • Web Debug Toolbar

    You can setup the symfony 2.0 sandbox on a local server in 7 steps under a local MAMPP environment on a Mac.

    The symfony sandbox is a Symfony project where all the required libraries and some simple controllers are already included and where the basic configuration is already done.

    1. Download the sandbox
    2. Unpack sandbox in your htdocs folder
    3. Check your local server environment with http://localhost:8888/sandbox/web/check.php
    4. Check a first webpage in the development environment at http://localhost:8888/sandbox/web/index_dev.php/
    5. The sandbox comes with a simple “Hello” app at http://localhost:8888/sandbox/web/index_dev.php/hello/Reinhold%20Weber
    6. Explore the web developer toolbar at the bottom (only available in the dev environment under index_dev)
    7. Configure a virtual host in conf/apache/httpd.conf which points to the sandbox/web/ directory

    Welcome to Symfony2.0, available in late 2010 – enjoy the ride. More on the new Symfony version soon.


  6. Write a simple Joomla 1.6 module from scratch

    June 28, 2010 by admin

    Create you first Joomla 1.6 module completely from scratch.

    Joomla, as of version 1.5 which was a complete rewrite is based on the MVC design pattern which makes creating modules extremely easy and structured. Joomla 1.6 changes a few things, the basics however remain the same.

    1. Create a folder called mod_helloworld in modules
    2. Create a mod_helloworld.php file
    3. Create a mod_helloworld.xml file
    4. Create a helper.php file
    5. Create a template file tmpl/default.php
    6. Discover new modules by going to “Extension Manager” -> “Discover”

    The code for mod_helloworld.php

    <?php
    defined('_JEXEC') or die; // no direct access allowed
     
    require_once dirname(__FILE__).DS.'helper.php'; // get helper files
     
    $hello = modHelloWorldHelper::getHello($params);
    require JModuleHelper::getLayoutPath('mod_helloworld');
    ?>

    The helper.php file

    <?php
    	class modHelloWorldHelper
    	{
    	    /**
    	     * Retrieves the hello message
    	     *
    	     * @param array $params An object containing the module parameters
    	     * @access public
    	     */    
    	    function getHello( $params )
    	    {
    	        return 'Hello, World!';
    	    }
    	}
    ?>

    Include the template file for the default view

    <?php
    defined('_JEXEC') or die;
    echo $hello; 
    ?>

    The helloworld.xml file

    	<?xml version="1.0" encoding="utf-8"?>
    	<extension type="module" version="1.6.0" client="site" method="upgrade">
    	    <name>Hello World!</name>
    	    <author>Reinhold Weber</author>
    	    <version>1.6.0</version>
    	    <description>Reinholds simple Hello World module.</description>
    	    <files>
    			 <filename module="mod_helloworld">mod_helloworld.php</filename>
    	        <filename>mod_helloworld.xml</filename>
    	        <filename>index.html</filename>
    	        <filename>helper.php</filename>
    	        <filename>tmpl/default.php</filename>
    	        <filename>tmpl/index.html</filename>
    	    </files>
    	    <params>
    	    </params>
    	</extension>

    Create both index.html files to prevent direct directory browsing

    <html><body></body></html>

  7. Create your first simple Drupal 7 module

    June 28, 2010 by admin

    Create your first Drupal 7 module with the following steps.

    1. Create a folder called helloworld in sites/all/modules/custom
    2. Create a helloworld.info file
    3. Create a template file page-helloworld.tpl.php in your theme directory
    4. Enable your module at http://domain.com/admin/build/modules
    5. Visit http://domain.com/helloworld

    This belongs into your helloworld.info file

    ; $Id$
     
    name = helloworld
    description = Reinholds Hello World module
    package = Reinholds modules
    core = 7.x
     
    files[] = helloworld.module

    The helloworld.module file

    <?php
    	function helloworld_menu(){
    	  $items = array();
     
    	  $items['helloworld'] = array(
    	    'title'            => t('Hello world'),
    	    'page callback'    => 'helloworld_output',
    	    'access arguments' => array('access content'),
    	  );
     
    	  return $items;
    	}
     
    	/*
    	* Display output
    	*/
    	function helloworld_output() {
    	  header('Content-type: text/plain; charset=UTF-8');
    	  header('Content-Disposition: inline');
    	  return 'helloworld';
    	}
    ?>

    The theme template file page-helloworld.tpl.php

    <?php
    print $content;
    ?>

  8. Drupal 7 Themes – Browser specific CSS

    June 28, 2010 by admin

    In Drupal 6 you had to target IE specific CSS files by adding lines to your page.tpl.php or use an additional module which allows you to target browsers inside your theme.info file.

    In Drupal 7 however, the recommended way is by using the use drupal_add_css() function in your template.php file.

    function mytheme_preprocess_html(&$vars) {
      drupal_add_css(path_to_theme() . '/fix-ie.css', array('weight' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
    }