Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Friday, 23 April 2010

How to ask questions the smart way

Found this absolutely fantastic article on how to ask questions on forums, newsgroups etc. in an intelligent and considered way that is more likely to get you a decent response.

Very good advice... http://www.catb.org/~esr/faqs/smart-questions.html

How to change the default JRE in Mac OS X (Leopard)

The problem was, my Eclipse installation was setup to use JRE 1.6 but when I checked using
mvn --version
it reported that it was using JRE 1.5. The solution's pretty simple in fact. The versions of Java JRE that are installed on your Mac are located in
/System/Library/Frameworks/JavaVM.framework/Versions
If you list the contents of the folder in terminal using
ls -al
then you'll see a symbolic link called "CurrentJDK" pointing to a symbolic link called "1.5" pointing to the latest version of 1.5 installed. Delete this link and recreate it pointing it to the symbolic link called "1.6" and you're done. The following code will achieve this.
 cd /System/Library/Frameworks/JavaVM.framwork/Versions/
sudo rm -r CurrentJDK
sudo ln -s 1.6 CurrentJDK
UPDATE Due to obvious confusion caused by my $ sign, I have reworked the code snippets to make them clearer

Saturday, 6 February 2010

Quick and easy server control

I use a macports installation of Apache2, PHP5 and MySQl5 for development on my macbooks. This is a great system and really simplifies the installation and setup the utilities.

However, the start/stop commands for each are not added to the PATH by default and it's tough remembering the long paths to the control programs.

But there's a solution:

  1. Open the Terminal
  2. Make sure that you're in your home folder.
  3. Edit (or create) .bash_profile


    $ nano .bash_profile
  4. Add aliases for your commands


    alias apache2ctl="sudo /opt/local/apache/bin/apachectl"
    alias mysqlstart="sudo /opt/local/bin/mysqld_safe5"
    alias mysqlstop="sudo /opt/local/bin/mysqladmin5 -u root -p shutdown"
  5. restart your bash session with


    source ~/.bash_profile
    and you're good to go...
Then you simply issue the following commands from the command line.
apache2ctl start # Start Apache
apache2ctl stop # Stop Apache
apache2ctl graceful # Restart Apache
mysqlstart # Start Mysql
mysqlstop # Stop Mysql

Friday, 15 January 2010

Find a user's IP address within an action

Simple one but took some time to find the answer so I'm noting it here.

You could of course use standard PHP but that defeats the point of using a framework in my opinion...

But the quick answer is
$request->getHttpHeader('addr', 'remote'));

Easy :)

Custom Validators and messages

Only a quick one now but there's a couple of points here that are worth noting. Especially as I've just been going round in circles for 30 minutes trying to get my custom message to display when a Doctrine form field was empty.

To be fair, I'm not confident it was due to it being a Doctrine field but anyway...

so...

1. If you use the 'addMessage()' method to add a custom method for an error code that is part of the default messages array within the validator base it WON'T get overwritten!!! If a default message exists it will always take precedence over the new version....

2. It's also worth remembering that the sfValidatorError (that your validator should extend from) class has it's clean() method called and this, in turn, calls the doClean() method. During the clean() method however, the isEmpty() method is called if the 'required' option is set to true. If the isEmpty() method returns true then your doClean() method won't ever be called... The way to get around this is to do one of the following:
a) set the 'required' option to false... not ideal if your value is required.
b) override the isEmpty() method to always return false and allow your doClean code to be called.

Done & Done