Friday, June 4, 2010

Debugging queries with symfony, doctrine and sprintf

Sometimes it is useful to see what parameters were passed to a query, using getSqlQuery we get the query with question marks and its annoying to then grab the query and play around with it... below is a quick fix for this problem, this purely a technique to save development time and you shouldn't leave var_dumps in your production code :)


var_dump(array(
'sql_query' => sprintf(
str_replace('?', '%s', $q->getSqlQuery()),
$parameter1, $parameter2, $parameter3
)
));

Thursday, June 3, 2010

Filtering JavaScript Arrays

Below is an example of how you can filter a JavaScript array using jQuery


var foo = new Array(5);
foo[0] = "zero";
foo[1] = "one";
foo[2] = "two";
foo[3] = "three";
foo[4] = "four";

alert(foo);

fooSelected = jQuery.grep(foo, function(value) {
return value != "three";
} );

alert(fooSelected);

Friday, May 28, 2010

No more print_r's or var_dumps to the web browser

Here is a neat way to dump objects to the log file instead of the browser, just add the following function to your actions class

class yourActions extends sfActions

/**
other code...
**/

/**
* Just a neater way of dumping objects to the log file instead of the browser
*
* @param $foobar
* @param $priority
* @author Richard Udovich
* @return void
* @see self::logMessage()
*/
public function logFoobar($foobar, $priority = 'info') {
if (in_array('Doctrine_Record', class_parents($foobar))) {
$table_name = $foobar->getTable()->getClassnameToReturn();
$this->logMessage('Dumping '.$table_name. "\n".print_r($foobar->toArray(), true).')', 'debug');
}
}

Tuesday, March 30, 2010

JS Bin - Collaborative JavaScript Debugging

Great tool allows you to quickly test out and collaborate javascript development, kind of like pastebin for javascript

Saturday, May 16, 2009

Setting symfony web root dynamically

class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
$this->setWebDir($this->getRootDir().DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.basename($_SERVER['DOCUMENT_ROOT']));

//$this->enableAllPluginsExcept(array('sfDoctrinePlugin', 'sfCompat10Plugin'));
$this->enableAllPluginsExcept(array('sfCompat10Plugin'));
}
}

Friday, October 10, 2008

Option "--theme" requires an argument

Getting this?

The execution of task "propel:generate-crud" failed.
- Option "--theme" requires an argument.
- Too many arguments ("propel:generate-crud app module class yourcustomtheme" given).

When running this?

symfony propel:generate-crud backend module class --non-atomic-actions --non-verbose-templates --theme=yourcustomtheme

Try:

symfony propel:generate-crud backend module class --non-atomic-actions --non-verbose-templates "--theme=yourcustomtheme"