Assign Symfony environments to (sub)domains 
Some projects need a staging site - somewhere where you can test and play around without messing up your database or webstats. Traditional applications require you to make a complete copy of your site to do this - and that means you need to sync your dev files with 2 remote locations.

With Symfony, for example, you can just point your staging domain or subdomain to the exact same location and set the environment on the fly.

This way you are using the exact same PHP files, but you have control over the usual environment settings such as database connection, application variables, email recipients etc etc.

In Symfony 1.2 you just modify your index.php controller like so:

<?php
##IP_CHECK##
require_once(dirname(__FILE__).'/../../config/ProjectConfiguration.class.php');

//check for DEMO site
$env = "live";
$debug = false;
$domain = $_SERVER['HTTP_HOST'];
if (strpos($domain,"demo") !== false){
$env = "demo";
$debug = true;
}

$configuration = ProjectConfiguration::getApplicationConfiguration('project_name', $env, $debug);
sfContext::createInstance($configuration)->dispatch();

Now just set your database in databases.yml

demo:
propel:
class: sfPropelDatabase
param:
dsn: mysql:dbname=demo_database;host=demo_server
username: demo_user
password: demo_pass
encoding: utf8
persistent: true
pooling: true
classname: DebugPDO


And finally, set your application settings in your app.yml

demo:
contact_email: contact@demo.com
#etc


If you want to make your staging/demo site appear differently, you can add a filter that inserts a stylesheet:

class demoFilter extends sfFilter
{
public function execute ($filterChain)
{
// execute this filter only once
$env = sfContext::getInstance()->getConfiguration()->getEnvironment();
if ($env = "demo" && $this->isFirstCall())
{
$this->getContext()->getResponse()->addStylesheet('demo','last');
}

// execute next filter
$filterChain->execute();
}
}


Note that the stylesheet should be set to 'last' to ensure you override your default styles.

You also need to add your filter to your filter.yml

rendering: ~
security: ~

demo:
class: demoFilter

#other filters go here

functional_test:
class: swFilterFunctionalTest

cache: ~
common: ~
execution: ~


The handy thing about using a filter is that you can apply it to multiple applications in the same project. Now you can set a background image in demo.css

body {
background-image: url(/images/demo.gif);
}

  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 3 / 127 )
PHPEdit has built-in Symfony CLI support 


Just got a press release from upstart IDE PHPEdit 3. They have built new support for Symfony, including a GUI for the CLI. It also has full YAML support and the ability to work intuitively with actions, controllers and templates. Just going to have to try this out!
  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 2.9 / 118 )
Search Symfony API from Firefox with OpenSearch 


Now you can search the Symfony API directly from the Firefox search box.
  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 3 / 113 )
Ajax form submission with extJS in Symfony 1.2 
Spent the last few days getting to know extJS a bit better and thought I'd share this little handy hint. Usually in Symfony 1.0 if you want to submit a form via ajax you can use "form_remote_tag()" to handle all the Protoype scripting for you. In Symfony 1.2 there is no remote form tag anymore, so you can wire up a remote_function() to a button onclick handler instead. You will need to serialize the form, too. However, if you're using extJS you might want to do all this from within a panel/window class. To do that, you roll your own JS function like this:

<?php echo javascript_tag(
"function submit_profile(){
Ext.getCmp('content_window').load({
url: '/user/updateProfile',
scripts: true,
params: Ext.Ajax.serializeForm('profile_form'),
text: 'Loading...'
})
}"
) ?>


Then in the success template you can drop a little more extJS:

<?php use_helper("Javascript"); ?>

<?php echo javascript_tag("
Ext.getCmp('content_window').close();
Ext.MessageBox.alert('Profile Updated', 'Changes saved successfully.', true);
"); ?>


In both cases the panel window object containing the form is called 'content_window'. Submitting the form updates the window and a successful post will close the window and show an alert.

Nice.
  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 3 / 101 )
Software RAID 0 drive mirroring in Windows XP 
I admit I am a Windows apologist but at least I hex edit my system files! Today I installed a second 1.5TB drive to mirror my primary data drive (you know, the one with all my work files, MP3s, virtual machines etc). Now Windows XP doesn't support RAID 0 out of the box, but that's just because it's disabled for workstation OSes. The capability is sitting there under the hood - and it works...



http://www.tomshardware.com/reviews/win ... 925-2.html

All you need is a hex editor and an XP boot CD to run the recovery console in. Now I feel slightly less concerned about my 1500GB single point of failure...
  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 2.9 / 65 )
Understand TCP/IP? Out of work? Want to fight terrorism? 
Well this is the job for you comrade!


ASIO is hiring!


  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 2.9 / 59 )
JavaScript sessions 
Well I would never have thought of it myself but this is an ingenious hack. By storing serialized data in the window.name parameter of the browser, you can have persistent data from page to page and - get this - across multiple domains. All without cookies. Food for thought there.

Meanwhile, you can have yourself a client-side session (until browser developers realise that 2MB+ is just way too big for a placeholder and lets face it this is a massive security risk which I'm sure is already well exploited by those who know about it).


  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 2.9 / 61 )
Using DBG for web based debugging and Xdebug for CLI debugging 
This is actually all I really wanted. To be able to use DBG in my IDE (PhpEd) and then have access to Xdebug in my command line scripts. Why? Because DBG is a great debugger and PhpEd is a great IDE, but Symfony requires Xdebug to do code coverage checks in its Lime testing framework. If you use PHPUnit you will find the same thing.

So I have apache configured to use DBG so I can debug from a browser and back.

Then I have a separate PHP.ini file that the command line accesses by specifying it in my windows PATH environment variable.

Now I have the best of both worlds and, if I ever really need to change, it's a matter of changing 2 lines in httpd.conf and restarting apache for those rare occasions. Not the holy grail, but it'll do for now.
  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 3 / 62 )
DBG and Xdebug living in harmony 
You may have tried this before and, like me, failed. But today I tried again, being a sucker for punishment, and . . . it worked! So don't believe everything you read on the internet (especially in forum posts from 2006!).
:)

2 days later....

After intermittent crashes in apache I decided that the harmony was not quite complete... so I came up with another solution which I'll put in my next post!
  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 2.9 / 53 )
Symfony URLs with dots 
If you need to pass an email address or use any URL with dots init, Symfony may get confused. This is actually a problem with the .htaccess setup and can be resolved simply by adding the following rule:

RewriteCond %{REQUEST_URI} !\..*/.*$

Thanks to the Symfony Google group for this one!
  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 3 / 51 )

Back Next