Warning: strpos() [function.strpos]: needle is not a string or an integer in /home/chaosorg/bugfeatures.com/blog/index.php on line 31

Warning: strpos() [function.strpos]: needle is not a string or an integer in /home/chaosorg/bugfeatures.com/blog/index.php on line 37
Bug Features - Free bug report and feature request service for your Web site.
More Symfony Mime type fun 
Sometimes I wonder about using mime types to validate file types. Usually using file extensions is more reliable seeing as though eah browser uses its own set of mime types fore each file extension anyway.

So here I am again modifying some core Symfony files to fix browser mime type inconsistencies, this time it's IE7 playing up. I mean honestly what's with image/x-png as a mime type?

But if you want to generate sfThumbnails you'll need to modify the sfGDAdapter class:


/**
* List of accepted image types based on MIME
* descriptions that this adapter supports
*/
protected $imgTypes = array(
'image/jpeg',
'image/pjpeg',
'image/png',
'image/x-png',
'image/gif',
);

/**
* Stores function names for each image type
*/
protected $imgLoaders = array(
'image/jpeg' => 'imagecreatefromjpeg',
'image/pjpeg' => 'imagecreatefromjpeg',
'image/png' => 'imagecreatefrompng',
'image/x-png' => 'imagecreatefrompng',
'image/gif' => 'imagecreatefromgif',
);

/**
* Stores function names for each image type
*/
protected $imgCreators = array(
'image/jpeg' => 'imagejpeg',
'image/pjpeg' => 'imagejpeg',
'image/png' => 'imagepng',
'image/x-png' => 'imagepng',
'image/gif' => 'imagegif',
);

  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 3 / 1214 )
Uploading ZIP files in Symfony 
It's rare that I feel the need to edit core symfony files, but this is one situation where it is the best choice. Symfony has a database of mime types it references when processing file uploads. It is pretty comprehensive, but the entries for ZIP files are:
application/x-zip-compressed
application/zip

To get Firefox uploads to work you need to add this:
application/x-zip

You can do this by adding it to the mime type array on the fly:
$mimeTypes['application/x-zip'] = 'zip';

Or even better, update the mime_types.dat file by adding this:
s:17:"application/x-zip";s:3:"zip";

And don't forget to increment the array count at the beginning of the file:
a:406:

  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 3.1 / 157 )
Working with the output buffer in Symfony 
AT first I thought I had found a bug in the way symfony decorates templates with layouts. But as usual, I discovered a bug in my own code :) Hopefully this will save someone else from having to debug a situation which turned out to be issue with using PHP's output buffer within a symfony action.

The problem: One of my actions was being rendered to the browser with the layout code (ie: html, head and body tags etc) in the middle of my template.

After debugging I discovered that symfony uses the output buffer to render templates, so if you mess with the buffer then you mess with the way your template gets rendered.

The renderFile() method if sfPHPView.class reads templates like this:
 ob_start();
ob_implicit_flush(0);
require($_sfFile);

return ob_get_clean();

I had a utility function that was using the buffer...
 ob_start();
//do stuff with the buffer

What I didn't realise was that Symfony had already called ob_start(), so my ob_start() was erasing the buffer and only sending output from that point onwards back to the render function.

The solution: If you ever need to capture the output buffer in Symfony, make sure you save the existing buffer and then render it back out when you are done.

My final code looked like this:
 $buffer = ob_get_clean();
ob_start();
//do stuff with the buffer
ob_clean();
echo $buffer;

OK it's pretty simple, but diagnosing it was for from simple!

  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 3 / 1227 )
Evaluating responseText in an extJS Ajax call 
Coming from a Prototype background I found extJS infuriating for some really basic tasks like this: calling a remote function and evaluating the response. In Prototype you just set evalScripts parameter to TRUE in the ajax call, but in extJS you have to jump through a few hoops.

The alternative is to use an updater, where you can set the scripts param to true, much like prototype. But if you're NOT updating a DOM element, then you have to do this:

Ext.Ajax.request({
url: '/module/action',
params: { id: my_id},
callback: function(options, success, response) {
var r = response.responseText;
if(window.execScript) {
window.execScript(r);
} else {
var global = this;
global.eval ? global.eval(r) : eval(r);
}
}
});


It's a pain, but it's rock solid!
  |  [ 0 trackbacks ]   |  permalink  |  related link  |   ( 3 / 1238 )
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 / 1154 )
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  |   ( 3 / 1145 )
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 / 1127 )
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 / 1124 )
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  |   ( 3 / 1056 )
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  |   ( 3 / 1056 )

Back Next