lundi 3 novembre 2008

Debug symfony / PHP applications with Eclipse + XDebug

Never wanted a PHP debugger as you have with JS debugger firebug ?

It is possible with Eclipse and XDebug php extension... ( thanks to this article )



Stack trace,
breakpoints,
watch expressions,
variables,
...












The steps :

Install Xdebug :

sudo apt-get install php5-xdebug


Then, edit extension's php config :

sudo vi /etc/php5/conf.d/xdebug.ini


And add just after the line 'zend_extension=...' :

xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"
xdebug.max_nesting_level=1000
xdebug.collect_params=2
xdebug.collect_return=On


Then, restart your Apache :

sudo /etc/init.d/apache2 restart



It's time to configure your Eclipse :


You surely will have to configure the Browser to 'external web browser' in your Preferences->General->Web Browser configuration.

use 'Run' menu or 'Debug' toolbar icon to access 'Open Debug Dialog'.

Make a 'New' PHP Web Page configuration

- edit the first tab ( server ) :

  • Choose XDebug as server debugger.
  • Make a new PHP Server if you have a virtualHost ( in my example: http://symfony.me )
  • Set 'File' Field to the absolute path of your front controller ( in my example: /var/www/symfony/web/frontend_dev.php )
  • Uncheck 'Break at first line'
  • Uncheck AutoGenerate URL to make it the same as when you debug your app ( in my example: http://symfony.me/frontend_dev.php/
- edit the second tab ( advanced ) :
  • check Open in browser
  • choose Start Debug from and add (in my example) : http://symfony.me/frontend_dev.php
  • check 'Continue Debug from this page'

That's It !

Now start debugging :

Add a breakpoint by right clicking a line number in your file -> toggle breakpoint.

the PHP debug perspective contains an Expression View where you can add your own watch expressions.

Discover the tool as I'm actually doing :) !

Modify project nature in eclipse

As said here, you can modify the .project file to add your builders, and the nature of the project.

This works for my eclipse PDT 3.3.2


<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>symfony</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.php.core.PhpIncrementalProjectBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.php.core.ValidationManagerWrapper</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.php.core.PHPNature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

lundi 20 octobre 2008

native sfPJS plugin in symfony 1.1

SfPJSPlugin is native in symfony 1.1, but documentation lacks.

Just use it by adding a template file of your module/yourAction named
yourActionSuccess.js.php
The content of this file -once rendered by php- has to be javascript.

example:


$(document).observe('dom:loaded', function() {
<?php include_partial('contact/init') ?>
EM = new EuroMineral.contact();
});


As you can see, you have access to php for generating JS...

To include this javascript in your response, use :
<?php use_dynamic_javascript('inscrit_demande/initBatiCodeList'); ?>

in your templates.

It just gives you the power of MVC separation and partials, components rendering in your js files.

vendredi 17 octobre 2008

add select column on manual join with Propel


$c = new Criteria;
$c->addJoin(InscritLignePeer::CAT, CategorieTarifPeer::CODE, Criteria::LEFT_JOIN);
InscritLignePeer::addSelectColumns($c);
$c->addSelectColumn(CategorieTarifPeer::LIBELLE);
$c->addAscendingOrderByColumn(InscritLignePeer::CAT);

$rs = InscritLignePeer::doSelectRS($c);

$this->inscrit_ligneList = array();
while ($rs->next())
{
$inscrit_ligne = new InscritLigne;
$colNum = $inscrit_ligne->hydrate($rs);
$inscrit_ligne->setCatLibelle($rs->getString($colNum));

$this->inscrit_ligneList[] = $inscrit_ligne;
}


and in your object class :


public function setCatLibelle($catLibelle='') {
$this->catLibelle = $catLibelle;
}

public function getCatLibelle() {
return $this->catLibelle;
}

mercredi 15 octobre 2008

Handle culture in symfony's routing



homepage:
url: /:sf_culture
requirements: { sf_culture: (?:fr|en|de) }
param: { module: dashboard, action: index, sf_culture: fr }

default_index:
url: /:sf_culture/:module
requirements: { sf_culture: (?:fr|en|de) }
param: { action: index }

default:
url: /:sf_culture/:module/:action/*
requirements: { sf_culture: (?:fr|en|de) }

lundi 13 octobre 2008



// when ajax working :
function() {
document.body.style.cursor = 'progress';
}

dimanche 12 octobre 2008

Lac du ballon

Par une belle après-midi d'automne,
on s'en est allé promener, à la recherche du bonheur, que je pense, nous avons éffleuré...

jeudi 2 octobre 2008

Sum method for Propel


public function getCumulDebit() {
$c = new Criteria;
$c->clearSelectColumns();
$c->addSelectColumn('SUM(' . EcriturePeer::MONTANT . ') AS total');
$c->add(EcriturePeer::NO_ADHERENT, $this->getNoEntreprise());
$c->add(EcriturePeer::CODE_DEBIT_CREDIT,'D');
$rs = EcriturePeer::doSelectRS($c);
$rs->next();
return $rs->getInt(1);
}