Search This Blog

Wednesday, February 23, 2011

cakePHP Cheet Sheet


          A CakePHP cheat sheet
(source:http://www.devdaily.com/php/cakephp-cheat-sheet-reference-page-examples)
===========================================
** CakePHP Default Directory Structure: **
===========================================

/app
app_controller.php
app_model.php
/config
acl.ini.php
bootstrap.php
core.php
databases.php
inflections.php
routes.php
/controllers
/components
your_components_here.php
your_controllers_here.php
/locale
/eng
/models
/behaviors
your_behaviors_here.php
your_models_here.php
/plugins
/tests
/cases
/behaviors
/components
/controllers
/helpers
/models
/fixtures
/groups
/tmp
/vendors
/views
/helpers
your_views_here.ctp
/webroot
/css
/files
/js
/cake
cake_core_files_are_in_here
/docs
release_notes_here
/vendors

===========================================
** CakePHP Naming Conventions **
===========================================

--- CakePHP Models

class names are singular
class names UpperCamelCased
filenames use a lower-case underscored syntax
database tables are plural underscored
set var $name in your model definition (PHP4)


--- CakePHP Controllers

class names are plural
class names are UpperCamelCased for multi-word controllers
class names also end with 'Controller'
file names use a lower-case underscored syntax
file names also end with '_controller.php'.


--- CakePHP Views

views are in folders that match controller
view folders are plural underscored
views are named after actions they display.
name the view file after action name, in lowercase.

===========================================
** CakePHP naming conventions - Examples **
===========================================

--- Assuming we have a database table named orders, the following standard
CakePHP naming conventions should be used:

Model
  filename  = order.php
  classname = Order
  directory = app/models

View
  filename  = (same as the action name in the controller)
  extension = .ctp (the filename extension)
  directory = app/views/orders

Controller
  filename  = orders_controller.php
  classname = OrdersController
  directory = app/controllers

--- Assuming we have a database table named order_items, the following standard
CakePHP naming conventions should be used:

Model
  filename  = order_item.php
  classname = OrderItem
  directory = app/models

View
  filename  = (same as the action name in the controller)
  extension = .ctp (the filename extension)
  directory = app/views/order_items

Controller
  filename  = order_items_controller.php
  classname = OrderItemsController
  directory = app/controllers


===========================================
** CakePHP bake Command Examples **
===========================================

cake bake

cake bake controller
cake bake model
cake bake view
cake bake project

cake bake controller orders
cake bake model order


===========================================
** CakePHP Foreign Key Examples and Relationship Types **
===========================================

*Relationship*  *Association Type*     *Example*
one to one      hasOne                 A user has one profile.
one to many     hasMany                A user can have multiple recipes.
many to one     belongsTo              Many recipes belong to a user.
many to many    hasAndBelongsToMany    Recipes have, and belong to many tags.

-- CakePHP relationship type examples:

# in a Post model class:

# each Post belongs to a User
var $belongsTo = array('User');

# TODO
var $hasOne ...

# in the User model
var $hasMany = array('Post');

# TODO
var $hasAndBelongsToMany

===========================================
** The CakePHP recursive attribute **
===========================================

*Value* *Meaning*
-1      returns only the current model, and ignores all associations.
 0      returns the current model, plus its owner(s).
 1      returns the current model, its owner(s), plus their associated models.
 2      returns the current model, its owner(s), their associated models,
        and the associated models of any associations.

-- In a simple controller index() method, the recursive attribute may be used
like this:

function index()
{
  $this->Post->recursive = 0;
  $this->set('posts', $this->paginate);
}

===========================================
** CakePHP find Examples **
===========================================

Name        Default  Description
type        'first'  can be 'all', 'first', or 'list'. determines what type of
                     find operation to perform. (TODO - more info here)

conditions  null     array containing the find (select) conditions as
                     key/value pairs

fields      null     array specifying which fields should be retrieved
                     in the resulting select query

order       null     sql 'order by conditions. field name must be
                     followed by ASC or DESC

page        null     page number, used for paged data

limit       null     a limit on the number of results returned, like
                     'select * from orders limit 20'.

offset      null     sql offset value (i haven't used this query much
                     myself, but i think it refers to skipping X
                     number of rows returned in a query)

recursive      1     the cakephp recursive value, relating to associated
                     model data

--- Code

$this->Post->find('all');

---------------------------------

$this->Post->find('all', array('conditions'=>array('User.id'=>5)));

---------------------------------

$this->Post->find('all', array('conditions'=>array('User.id'=>'<> 5')));

---------------------------------

# this is a little lame, but i'm trying to avoid dates
$this->Post->find('all', array('conditions'=>array('User.id'=>1, 'Post.id'=>'>
50')));

---------------------------------

$this->Post->find('all',
                  array('conditions'=>array('User.id'=>5),
                        'fields'=>'Post.name',
                        'order'=>'Post.id ASC',
                        'limit'=>20,
                        'recursive'=>0));
---------------------------------

# note: you can search for date or datetime fields by enclosing the table's
field name
#       in the SQL DATE() function.
$this->Post->find('all', array('conditions'=>array('User.id'=>5,
'DATE(Post.date)'=>'CURDATE()')));

---------------------------------

CakePHP find queries with ORDER BY examples:

array('order'=>'date ASC')
array('order'=>'date DESC')
array('order'=>'User.id DESC')

---------------------------------

These CakePHP find examples are lines of code that would be used in an
OrderController class:

$this->Order->find('all');
$this->Order->find(null, null, 'date DESC');
$this->Order->find('all', array('conditions'=>array('User.id'=>1)));
$this->Order->find('all',
array('conditions'=>array('User.id'=>array(1,2,3,4))));
$this->Order->find('all', array('conditions'=>array('User.id'=>'<> 1')));
$this->Order->find('all', array('conditions'=>array('User.id'=>1,
'DATE(Post.date)'=>'CURDATE()')));
$this->Order->find('all', array('order'=>'date ASC', 'limit'=>20,
'recursive'=>0);

---------------------------------

$params can contain all these:

array(
  'conditions' => array('Model.field' => $thisValue), //array of conditions
  'recursive' => 1, //int
  'fields' => array('Model.field1', 'DISTINCT Model.field2'), //array of field
  names
  'order' => array('Model.created', 'Model.field3 DESC'), //string or array
  defining order
  'group' => array('Model.field'), //fields to GROUP BY
  'limit' => n, //int
  'page' => n, //int
  'offset'=>n, //int  
  'callbacks' => true //other possible values are false, 'before', 'after'
)

---------------------------------

# find('first', $params) syntax

function some_function() {
  ...
  $this->Article->order = null; // resetting if it's set
  $semiRandomArticle = $this->Article->find();
  $this->Article->order = 'Article.created DESC'; // simulating the model having
  a default order
  $lastCreated = $this->Article->find();
  $alsoLastCreated = $this->Article->find('first', array('order' =>
  array('Article.created DESC')));
  $specificallyThisOne = $this->Article->find('first', array('conditions' =>
  array('Article.id' => 1)));
  ...
}

---------------------------------

# find('count', $params)

function some_function() {
   ...
   $total = $this->Article->find('count');
   $pending = $this->Article->find('count', array('conditions' =>
   array('Article.status' => 'pending')));
   $authors = $this->Article->User->find('count');
   $publishedAuthors = $this->Article->find('count', array(
      'fields' => 'DISTINCT Article.user_id',
      'conditions' => array('Article.status !=' => 'pending')
   ));
   ...
}

---------------------------------

# find('all', $params) syntax

function some_function() {
   ...
   $allArticles = $this->Article->find('all');
   $pending = $this->Article->find('all', array('conditions' =>
   array('Article.status' => 'pending')));
   $allAuthors = $this->Article->User->find('all');
   $allPublishedAuthors = $this->Article->User->find('all', array('conditions'
   => array('Article.status !=' => 'pending')));
   ...
}

---------------------------------

# find('list', $params) syntax

function some_function() {
   ...
    $allArticles = $this->Article->find('list');
    $pending = $this->Article->find('list', array(
        'conditions' => array('Article.status' => 'pending')
    ));
    $allAuthors = $this->Article->User->find('list');
    $allPublishedAuthors = $this->Article->find('list', array(
        'fields' => array('User.id', 'User.name'),
        'conditions' => array('Article.status !=' => 'pending'),
        'recursive' => 0
    ));
   ...
}

===========================================
** CakePHP paginate Examples **
===========================================

A basic CakePHP paginate method in a controller:

function index() {
  $this->Order->recursive = 0;
  $this->set('orders', $this->paginate());
}

---------------------------------

class RecipesController extends AppController {

    var $paginate = array(
        'limit' => 25,
        'order' => array(
            'Post.title' => 'asc'
        )
    );
}

--- or this:

class RecipesController extends AppController {

    var $paginate = array(
        'fields' => array('Post.id', 'Post.created'),
        'limit' => 25,      
        'order' => array(
            'Post.title' => 'asc'
        )
    );
}

===========================================
** CakePHP logging **
===========================================

CakeLog::write('debug', 'Something did not work');

---------------------------------

$this->log("Something did not work!", 'debug');

---------------------------------

Configure::write('log', E_WARNING);


===========================================
** CakePHP Global Methods **
===========================================

__(string $string_id, boolean $return = false) — function handles localization

config('some_file', 'myconfig') — Can be used to load files from your
application config-folder via include_once

convertSlash(string $string) — Converts forward slashes to underscores and
removes the first and last underscores in a string

uses(string $lib1, $lib2, $lib3...) — Used to load CakePHP's core libraries
(found in cake/libs/).

debug(mixed $var, boolean $showHtml = false) - If the application's DEBUG level
is non-zero, $var is printed out.

a(mixed $one, $two, $three...) — Returns an array of the parameters used to
call the wrapping function

aa(string $one, $two, $three...) — Used to create associative arrays formed
from the parameters used to call the wrapping function.

am(array $one, $two, $three...) — Merges all the arrays passed as parameters
and returns the merged array.

e(mixed $data) — Convenience wrapper for echo()

env(string $key) — Gets an environment variable from available sources

ife($condition, $ifNotEmpty, $ifEmpty) — Used for ternary-like operations

low(string $string) — Convenience wrapper for strtolower()

up(string $string) — Convenience wrapper for strtoupper()

r(string $search, string $replace, string $subject) — Convenience wrapper for
str_replace()

h(string $text, string $charset = null) — Convenience wrapper for
htmlspecialchars()

pr - shortcut for print_r()

stripslashes_deep(array $value) — Recursively strips slashes from the supplied
$value. Returns the modified array.

fileExistsInPath(string $file) — Checks to make sure that the supplied file is
within the current PHP include_path



===========================================
** CakePHP Global Constants **
===========================================

ACL_CLASSNAME
ACL_FILENAME
APP
APP_DIR
APP_PATH
AUTO_SESSION
CACHE
CACHE_CHECK
CAKE
CAKE_CORE_INCLUDE_PATH
CAKE_SECURITY
CAKE_SESSION_COOKIE
CAKE_SESSION_SAVE
CAKE_SESSION_STRING
CAKE_SESSION_TABLE
CAKE_SESSION_TIMEOUT
COMPONENTS
COMPRESS_CSS
CONFIGS
CONTROLLER_TESTS
CONTROLLERS
CORE_PATH
CSS
DATASOURCE
DAY
DEBUG
DS
ELEMENTS
HELPER_TESTS
HELPERS
HOUR
INFLECTIONS
JS
LAYOUTS
LIB_TESTS
LIBS
LOG_ERROR
LOGS
MAX_MD5SIZE
MINUTE
MODEL_TESTS
MODELS
MODULES
MONTH
ROOT
SCRIPTS
SECOND
TAG_DIV
TAG_FIELDSET
TAG_LABEL
TAG_P_CLASS
TESTS
TMP
VENDORS
VIEWS
WEBROOT_DIR
WEBSERVICES
WEEK
WWW_ROOT
YEAR

===========================================
** CakePHP Controller properties, methods, callbacks **
===========================================

--- CakePHP controller properties:

$name = null
$action = null
$autoLayout = true
$autoRender = true
$base = null
$beforeFilter = null
$cacheAction = false
$components = array()
$data = array()
$helpers = array('Html')
$here = null
$layout = 'default'
$output = null
$pageTitle = false
$params = array()
$persistModel = false
$plugin = null
$uses = false
$view = 'View'
$viewPath = null
$webroot = null
$_viewClass = null
$_viewVars = array()

--- CakePHP controller methods

cleanUpFields ()
constructClasses ()
flash ($message, $url, $pause = 1)
flashOut ($message, $url, $pause = 1)
generateFieldNames ($data = null, $doCreateOptions = true)
postConditions ($data, $operator = '', $bool = 'AND', $exclusive = false)
redirect ($url, $status = null)
referer ($default = null, $local = false)
render ($action = null, $layout = null, $file = null)
set ($one, $two = null)
setAction ($action)
validate ()
validateErrors ()

--- CakePHP controller callbacks

afterFilter ()
beforeFilter ()
beforeRender ()


===========================================
** CakePHP Model properties, methods, callbacks, and validation **
===========================================

--- CakePHP Model properties:

$belongsTo = array()
$cacheQueries = true
$data = array()
$displayField = null
$hasAndBelongsToMany = array()
$hasMany = array()
$hasOne = array()
$id = false
$logTransactions = false
$name = null
$primaryKey = null
$recursive = 1
$useDbConfig = 'default'
$useTable = null
$validate = array()
$validationErrors = array()

--- CakePHP Model methods:

bindModel ($params)
create ()
delete ($id = null, $cascade = true)
escapeField ($field)
execute ($data)
exists ()
field ($name, $conditions = null, $order = null)
find ($conditions = null, $fields = null, $order = null, $recursive = null)
findAll ($conditions = null, $fields = null, $order = null, $limit = null, $page
= 1, $recursive = null)
findAllThreaded ($conditions = null, $fields = null, $sort = null)
findCount ($conditions = null, $recursive = 0)
findNeighbours ($conditions = null, $field, $value)
generateList ($conditions = null, $order = null, $limit = null, $keyPath = null,
$valuePath = null)
getAffectedRows ()
getColumnType ($column)
getColumnTypes ()
getDisplayField ()
getID ($list=0)
getLastInsertID ()
getNumRows ()
hasAny ($conditions = null)
hasField ($name)
invalidate ($field)
invalidFields ($data = array())
isForeignKey ($field)
loadInfo ()
query ()
read ($fields = null, $id = null)
remove ($id = null, $cascade = true)
save ($data = null, $validate = true, $fieldList = array())
saveField ($name, $value, $validate = false)
set ($one, $two = null)
setDataSource ($dataSource = null)
setSource ($tableName)
unbindModel ($params)
validates ($data=array())
setSource ($tableName)

--- CakePHP Model callbacks

afterDelete ()
afterFind ($results)
afterSave ()
beforeDelete ()
beforeFind (&$queryData)
beforeSave ()
beforeValidate ()

--- CakePHP Model validation

'VALID_EMAIL`
'VALID_NOT_EMPTY`
'VALID_NUMBER`
'VALID_YEAR`



===========================================
** CakePHP View properties and methods **
===========================================

--- CakePHP View properties

$action = null
$autoLayout = true
$autoRender = true
$base = null
$controller = null
$ext = '.thtml'
$hasRendered = null
$helpers = array('Html')
$here = null
$layout = 'default'
$loaded = array()
$models = array()
$name = null
$pageTitle = false
$params
$parent = null
$plugin = null
$subDir = null
$themeWeb = null
$uses = false
$viewPath

--- CakePHP View methods

element ($name)
error ($code, $name, $message)
pluginView ($action, $layout)
render ($action = null, $layout = null, $file = null)
renderCache ($filename, $timeStart)
renderElement ($name, $params = array())
renderLayout ($content_for_layout)
setLayout ($layout)



===========================================
** CakePHP Data Validation **
===========================================

<?php
class User extends AppModel {
    var $name = 'User';
    var $validate = array(
        'login' => 'alphaNumeric',
        'email' => 'email',
        'born' => 'date'
    );
}
?>



===========================================
** CakePHP Helpers **
===========================================

--- CakePHP Html Helper

addCrumb ($name, $link)
charset ($charset, $return = false)
checkbox ($fieldName, $title = null, $htmlAttributes = null, $return = false)
css ($path, $rel = 'stylesheet', $htmlAttributes = null, $return = false)
dateTimeOptionTag ($tagName, $dateFormat = 'DMY', $timeFormat = '12', $selected
= null, $selectAttr = null, $optionAttr = null, $showEmpty = true)
dayOptionTag ($tagName, $value = null, $selected = null, $selectAttr = null,
$optionAttr = null, $showEmpty = true)
file ($fieldName, $htmlAttributes = null, $return = false)
formTag ($target = null, $type = 'post', $htmlAttributes = null)
getCrumbs ($separator = '»', $startText = false, $return = false)
guiListTree ($data, $htmlAttributes = null, $bodyKey = 'body', $childrenKey =
'children', $return = false)
hidden ($fieldName, $htmlAttributes = null, $return = false)
hourOptionTag ($tagName, $value = null, $format24Hours = false, $selected =
null, $selectAttr = null, $optionAttr = null, $showEmpty = true)
image ($path, $htmlAttributes = null, $return = false)
input ($fieldName, $htmlAttributes = null, $return = false)
link ($title, $url = null, $htmlAttributes = null, $confirmMessage = false,
$escapeTitle = true, $return = false)
linkEmail ($title, $email = null, $options = null)
meridianOptionTag ($tagName, $value = null, $selected = null, $selectAttr =
null, $optionAttr = null, $showEmpty = true)
minuteOptionTag ($tagName, $value = null, $selected = null, $selectAttr = null,
$optionAttr = null, $showEmpty = true)
monthOptionTag ($tagName, $value = null, $selected = null, $selectAttr = null,
$optionAttr = null, $showEmpty = true)
parseHtmlOptions ($options, $exclude = null, $insertBefore = ' ', $insertAfter =
null)
password ($fieldName, $htmlAttributes = null, $return = false)
radio ($fieldName, $options, $inbetween = null, $htmlAttributes = array(),
$return = false)
selectTag ($fieldName, $optionElements, $selected = null, $selectAttr = null,
$optionAttr = null, $showEmpty = true, $return = false)
setFormTag ($tagValue)
submit ($caption = 'Submit', $htmlAttributes = null, $return = false)
tableCells ($data, $oddTrOptions = null, $evenTrOptions = null, $return = false)
tableHeaders ($names, $trOptions = null, $thOptions = null, $return = false)
tagErrorMsg ($field, $text)
tagIsInvalid ($model, $field)
tagValue ($fieldName)
textarea ($fieldName, $htmlAttributes = null, $return = false)
trim ()
url ($url = null, $return = false)
validate ()
validateErrors ()
yearOptionTag ($tagName, $value = null, $minYear = null, $maxYear = null,
$selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true)
_parseAttributes ($options, $exclude = null, $insertBefore = ' ', $insertAfter =
null)

--- CakePHP Form Helper

button ($params, $type= 'button', $options=array())
create ($model=null, $options=array())
dateTime ($tagName, $dateFormat= 'DMY', $timeFormat= '12', $selected=null,
$attributes=array(), $showEmpty=true)
day ($fieldName, $selected=null, $attributes=array(), $showEmpty=true)
end ($options=null)
error ($field, $text=null, $options=array())
file ($fieldName, $options=array())
hidden ($fieldName, $options=array())
hour ($tagName, $format24Hours=false, $selected=null, $attributes=array(),
$showEmpty=true)
input ($tagName, $options=array())
inputs ($fields=null, $blacklist=null)
isFieldError ($field)
label ($tagName=null, $text=null, $attributes=array())
meridian ($tagName, $selected=null, $attributes=array(), $showEmpty=true)
minute ($tagName, $selected=null, $attributes=array(), $showEmpty=true)
month ($tagName, $selected=null, $attributes=array(), $showEmpty=true)
password ($fieldName, $options=array())
secure ($fields)
select ($fieldName, $options=array(), $selected=null, $attributes=array(),
$showEmpty= '')
submit ($caption= 'Submit', $options=array())
submitImage ($path, $options=array())
text ($fieldName, $options=array())
textarea ($fieldName, $options=array())
year ($fieldName, $minYear=null, $maxYear=null, $selected=null,
$attributes=array(), $showEmpty=true)

--- CakePHP Ajax Helper

autoComplete ($field, $url="", $options=array())
div ($id, $options=array())
divEnd ($id)
drag ($id, $options=array())
drop ($id, $options=array())
dropRemote ($id, $options=array(), $ajaxOptions=array())
editor ($id, $url, $options=array())
form ($params=null, $type= 'post', $options=array())
isAjax ()
link ($title, $href=null, $options=array(), $confirm=null, $escapeTitle=true)
observeField ($field_id, $options=array())
observeForm ($field_id, $options=array())
remoteFunction ($options=null)
remoteTimer ($options=null)
slider ($id, $track_id, $options=array())
sortable ($id, $options=array())
submit ($title= 'Submit', $options=array())

--- CakePHP Text Helper

highlight ($text, $phrase, $highlighter= '< span class="highlight">\1</span >')
stripLinks ($text)
autoLinkUrls ($text, $htmlOptions = array())
autoLinkEmails ($text, $htmlOptions = array())
autoLink ($text, $htmlOptions = array())
truncate ($text, $length, $ending = '...', $exact = true)
trim ()
excerpt ($text, $phrase, $radius = 100, $ending = "...")
flay ($text, $allowHtml = false)

--- CakePHP Time Helper

dayAsSql ($date_string, $field_name, $return = false)
daysAsSql ($begin, $end, $field_name, $return = false)
fromString ($date_string)
isThisYear ($date_string, $return = false)
isToday ($date_string, $return = false)
isTomorrow ($date_string, $return = false)
nice ($date_string=null, $return = false)
niceShort ($date_string=null, $return = false)
relativeTime ($datetime_string, $format = 'j/n/y', $return = false)
timeAgoInWords ($datetime_string, $format = 'j/n/y', $backwards = false, $return
= false)
toAtom ($date_string, $return = false)
toRSS ($date_string, $return = false)
toUnix ($date_string, $return = false)
trim ($string, $length, $ending = '..')
wasWithinLast ($timeInterval, $date_string, $return = false)
wasYesterday ($date_string, $return = false)

--- CakePHP Number Helper

precision ($number, $precision = 3)
toReadableSize ($size)
toPercentage ($number, $precision = 2)


===========================================
** CakePHP Components **
===========================================

--- CakePHP Session Component

check ($name)
del ($name)
delete ($name)
error ()
flash ($key)
read ($name)
renew ()
setFlash ($flashMessage, $layout = 'default', $param = null, $key = 'flash')
valid ()
write($name, $value)

--- CakePHP RequestHandler Component

accepts ($types)
getAjaxVersion ()
getClientIP ()
getReferer ()
isAjax ()
isAtom ()
isDelete ()
isGet ()
isMobile ()
isPost ()
isPut ()
isRss ()
isXml ()
setContent ($name, $type)
stripAll ($string)
stripImages ($string)
stripScripts ($string)

--- CakePHP Security Component

requirePost ([$action1, $ action2, $action3, ...])
requireAuth ([$action1, $ action2, $action3, ...])

--- CakePHP ACL Component

check ($aro, $aco, $action="*")
allow ($aro, $aco, $action="*")
deny ($aro, $aco, $action="*")
inherit ($aro, $aco, $action="*")
grant ($aro, $aco, $action="*")
revoke ($aro, $aco, $action="*")
getAro ($id)
getAco ($id)

Tuesday, February 22, 2011

Task only showing 99.99% complete - dotProject Problem in 2.1 version

When we select progress as 100% in view mode, it then reports the task as 99.99%. Have we missed a step to get it to show as 100% This is a problem in dotproject due to the column datatype to fix this run the sql below which will change the datatype of percentage column from 4 to 5 and also update the previous data of 99.99 to 100

"ALTER TABLE `tasks` MODIFY `task_percent_complete` decimal(5,2) DEFAULT '0';
update tasks set task_percent_complete = 100 where task_percent_complete = 99.99;"

How to Run Apps & Games on Your China Mobile Phone (Mtk).

Hey.... first let's check whether you can run apps and games on your phone...

to check type *#220807# when on the desktop...If a webpage starts to load/an application window pops up , it means

your phone can run apps and games,,,

If an application window popped up you can skip step 1 and directly go to step 2... but if a webpage started to load you must follow step 1..

Step1:-

First download the file DSM_GM.mrp .. just search DSM_GM.mrp on google... you will find it..after downloading

put it on the 'mythroad' folder//.. it can be found on your memcard inserted on the phone..

step 2:-

Download .mrp format files and apps (available on mrpcn.com-translate using translate.google.com)

step 3:-

copy them to the 'mythroad' folder found on the memcard

Final step:-

dial *#220807#..

on the menu that appears click on the desired application and it will launch..


Friday, February 18, 2011

How to install Zend framework with XAMPP

I, like most web developers, use the excellent XAMPP to develop and test PHP/MySQL websites and applications on my local machine. The problem is the XAMPP doesn’t come with the Zend framework installed by default.

If you want to develop with Zend, you could always use Zend Server CE instead of XAMPP, as Zend Server comes with the Zend framework installed. The downside to that is that the Zend server is not as simple to set up and use as XAMPP, and if you’ve already been using XAMPP, migrating to Zend server can be a real pain in the ass, and you can’t run both XAMPP and Zend server together.

If you google installing Zend in XAMPP, there are many different guides, all of which seem overly complicated. Installing the zend framework under XAMPP is actually a lot simpler than most guides online would suggest, and using the following guide you should be able to run Zend Apps in your existing XAMPP environment in a matter of minutes.

Step 1 – Locate your PHP include path.

This is the location the Zend framework needs to be installed to. You can easily find your include path by going tohttp://localhost/ (with XAMPP running) and clicking the phpinfo() link on the left menu. Near the top of that page, under the core heading will be row called “include_path”, the value in the column next to it is the one you want, eg: “C:\xampp\php” in windows or ”/opt/lampp/lib/php” in linux.

Step 2 – Download and extract the Zend framework.

You can download the Zend framework for free here: http://framework.zend.com/download/latest, I’d recommend downloading the full package, as keeping things light weight isn’t imperative on a test/development environment, and that way you’ll be less likely to need to add anything in the future. Once the Zend framework has downloaded, extract it, and you should get a folder called somthing like “ZendFramework-1.10.4″, obviously the version numbers may be different.

Step 3 – Install Zend to your PHP include path.

Now all you have to do in copy the relevent Zend files to your PHP include path. To find the files you need to copy, open up you extracted Zend framework download, find the ‘library’ folder and open that. In that folder there is a folder called ‘Zend’, you’ll need to copy that entire folder to your PHP include path.

If you’re using windows that should be a simple drag and drop into your PHP include path. If you’re using linux, you’ll need to copy using sudo, eg: “sudo cp -r Zend/ /opt/lampp/lib/php”.

If it all went to plan you will now have a folder called ‘Zend’ in your PHP include folder and your Zend framework is ready to go. Told you it was easy.


Expand-collapse toggle panel (div) using jquery | jquery toggle

In this post, I’ll show you how easy it is to show expandable and collapsible toggle panel using jQuery. When you click on the heading, the content gets displayed by sliding and when you again click on the heading again, it gets collapsed.
Now let’s look at the html code,
<div class="msg_list">
<p class="msg_head">Header-1 </p>
<div class="msg_body">
orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit</div>
<p class="msg_head">Header-2</p>
<div class="msg_body">
orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit</div>
<p class="msg_head">Header-3</p>
<div class="msg_body">
orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit</div>
</div>
As you can see above, the whole message panes contained inside the div with class name “msg_list”. And, the header element where you click is defined with the class “msg_head” and after that there is element with class “msg_body” which contains the message or text which is expandable or collapsible.
Now let’s look at the CSS attributes of these three classes,
p {
padding: 0 0 1em;
}
.msg_list {
margin: 0px;
padding: 0px;
width: 383px;
}
.msg_head {
padding: 5px 10px;
cursor: pointer;
position: relative;
background-color:#FFCCCC;
margin:1px;
}
.msg_body {
padding: 5px 10px 15px;
background-color:#F4F4F8;
}
Now, let’s look at the JavaScript code to make the pane toggling i.e collapsible and expandable,
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
  //hide the all of the element with class msg_body
  $(".msg_body").hide();
  //toggle the componenet with class msg_body
  $(".msg_head").click(function()
  {
    $(this).next(".msg_body").slideToggle(600);
  });
});
</script>
As you can see above, first of all jQuery framework is used. After that, all the element with the class name “msg_body” is collapsed when the page is loaded. And you can see, the “slideToggle()” function of jQuery is used to expand and collapse the “div” with class “msg_body”. When user clicks on the element with the class “.msg_head”, then div with class “msg_body” next to it, gets toggled with sliding effect, making toggle panel using jQuery.