home | contact us
» » April


If like me you kicked off your Zend Framework experience with the Quick Start and have kept the error controller system of the Quick Start for your other ZF projects, you might find this little snippet useful.

The Quick Start uses the Exception::getTraceAsString() method to give you the stack trace. Unfortunately this function seems to snip off a bit of useful info.. almost tantalising you with the info but not quite giving you enough to actually know what is going wrong!

To get a more detailed stack trace, I recommend changing this and using the Exception::getTrace() function which returns and array of the trace. You can then echo out all of this info in full.

For me (as I have xdebug for my dev environment, which is the only place you should be dumping stack traces anyway) I use the following chunk of code in my views/scripts/error/error.phtml

<? // application/views/scripts/error/error.phtml ?>

<h1>An error occurred</h1> 
<h2><?= $this->message ?></h2> 

<? if ('production' != $this->env): ?>
    <h3>Exception information:</h3> 
    <p> 
        <b>Message:</b> <?= $this->exception->getMessage() ?> 
    </p> 
    <h3>Request Parameters:</h3> 
    

		



    <h3>Stack Trace 2:</h3>
    <?php
    foreach($this->exception->getTrace() as $t){
        var_dump($t);
    }
    ?>
<? endif ?>


 

This is my favourite source for hi resolution desktop images. Some really nice pictures and all available in resolutions to suit whichever display you have.

http://interfacelift.com

More…


 

I have recently been messing around trying to figure out the best way of running long processes within a Zend Framework App.

Usually I would code in regular flush(); commands to make sure that the browser didnt time out and also that the user can see that something is happening.

However, the standard MVC structure of the default ZF application system wraps the entire response in an output buffer which is only flushed once everything is done. This has lots of advantages including allowing to add extra headers (FirePHP) on the fly throughout the application process.

For long running scripts though, it is important for me to flush output. My solution to this is twofold.

Firstly set up an ‘output’ action in my base controller. The output action is looking for an ‘act’ parameter in its view script. This act param is then used to generate a url string based on the current controller and the action as the act param. This url string is then used to create an iframe which will be used to output the flushing results of the long running script.

For the long running script action itself, I am going to disable layout and also disable view render. Its really important to switch both of these off.

The following needs to be declared at the top of any action that you intend to be viewed via the output iframe.

    // accessed via output action
    public function longrunningAction(){
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_model->grabImages();
    }

Now I am free to echo out basic HTML and also call flush from within my model. To flush the output you need to call both ob_flush() and then flush(). To make this easier I set up a static method in my static Tools class

    public static function flush(){
        ob_flush();
        flush();
    }

One issue I have had though is that any time the ZF internals try to add a header, you will get a basically meaningless exception telling you that headers have already been sent. It doesn’t tell you what header was attempted to be added or why, so you can be left out in the cold a bit when trying to debug.

If anyone knows a good workaround for this, or can offer a better solution for handling these long running processes I would love to hear about it.

More…


 

Check out this little snippet of htaccess code to force SSL usage. Works regardless of port.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

More…


 

If you are administering a plesk server running version 8.x then you are likely dealing with phpMyAdmin version 2.8.x.x which has a bug that prevents you from performing database copy operations due to one missing space in the generated SQL.

One possible solution here is to simply install phpMyAdmin in its own right and of course use the latest version which has resolved this bug.

If however you would rather not bother with that, you can do this quite easily from the command line using the following commands.

First the SQL query:

CREATE DATABASE db2;

Then, from the command-line, do the following:

$ mysqldump -u root --password=pass db1 | mysql -u root --password=pass db2

I suppose you could start hacking on the bundled phpMyAdmin source code to fix the bug without upgrading the whole version… Ever looked at the phpMyAdmin source code?

:-)

More…


 

Update

Just use Banshee, it seems to work fine and its actually pretty slick :)

BTW – to format your X-FI, just start it up whilst holding down the play/pause button to get into “recovery mode” the rest is easy

Original Blog

I have now decided to totally abandon my windows installation and use Linux for everything. I was pretty much using Linux for everything already but there were a few apps that I still used windows for or simply hadn’t got around to trying out on Linux.

I have a projector hooked up for watching movies. I used to use windows XP for this but the windows driver for my Nvidia GT 9400 started to get really picky about giving me dual view, requiring reboots to get it to work properly. With the release of Jaunty and SOAS boot times, my windows XP partition was starting to look like a really unattractive solution. Its probably infected with conficker and god knows what else anyway.

Thankfully the Nvidia driver and admin software for Linux is actually really good. It needs to be launched as Sudo to work properly – simply edit the launcher and prepend gksudo before the command to give you a GUI sudo box. That’s the projector and dual view taken care of (note you need to enable Xineview or whatever its called to get a proper desktop stretching across both monitors.)

Now the last little thing is my Creative ZEN X-Fi 16GB mp3 player. I love that little box of tricks and don’t often feel the need to update the music on there as its got such a generous storage capacity. However I came to do it, plugged it in and it wasn’t picked up as a removable drive as I thought it might be. A quick search later and I discover a programme called gnomad2.

“Gnomad 2 is a GUI built on top of GTK/GNOME 2, id3lib and libnjb that
makes it possible to transfer tracks and files from/to a Creative
Nomad Jukebox (all brands). It is designed much like an ordinary
graphical FTP program.

You can find it in syntaptic package manager. Install this and also edit the command to gksudo and you should then be able to move your music around freely. Oh yeah it runs a damn site faster than the creative windows software – sweet :-)

Windows already feels like a distant memory…

More…


 

I’ve been using the beta of Ubuntu Jaunty for about a month now and its been great. I’m now upgrading my standard Ubuntu installs with this latest edition which went live today.

Many thanks to all the team at Canonical for continuing to produce an excellent open source desktop environment.

More…


 

The scenario here is that you have access to two servers – old and new – and you want to copy a site + database from old server to new server directly.

You have root SSH access to both servers.

1. Create a TAR archive of the document root for the site on the old server.
Log into SSH on the old server.

Navigate to your vhost root (the folder just above httpdocs) then use the following command to make a tar archive of your entire httpdocs folder:

tar -cvvf httpdocs.tar httpdocs/

2. Gzip the TAR archive

 gzip httpdocs.tar

3. Transer the File to the New Server
Log into SSH on the new server

This bit may change according to your specific server setups. The way I approached this was to log into the new server at the vhost root where I want to import the old httpdocs folder. I then use the following SCP command to log into the old server, find my archive and copy it to the current location.

I am using a custom port (not the real one in the example of course) for SSH so that must be specified. Unlike SSH, you must use a capital P to specify a custom port

Note the space and full stop at the end – they are very important!

scp -P 1111 old_server_username@123.123.123.123:/path/to/file/on/old/server/archive.tar.gz .

4. Dump all DB’s and Transfer
To dump all of the databases into one single file we can use the following mysqldump syntax. Note you can simply use the –all-databases switch but this will backup database that you probably don’t want to include. Better to declare a list of all the DB’s that you do want.

mysqldump -u SomeUser -p --databases mydb1 mydb2 mydb3 > myDbs.sql

Once you have this dump file you can Gzip it and transfer it via SCP using the same kind of commands as above.

More…


 

I use this little function as part of my base form class to enable me to easily lock certain form elements.

    public function lockField($field){        
        $elem = $this->getElement($field);        
        $elem->setAttrib('disabled', true);
        $elem->setAttrib('readonly',true);
    }

usage might be like the following:

public function makeForm($action){
	$form = new My_Form(array('action'=>$action));
	$form->addElement(.. custom form add element function);
	$form->lockField('fieldname');
	$form->addSubmit(.. custom add submit function);
	return $form;
}

 

It looks like Magento sites have a weakness where they throw a fatal error on the admin side if they can not connect to the Magentocommerce site to check for updates.

I will post the solution to this shortly, but Magento – please make sure this is fixed ASAP.


 
rss icon