Installing composer to an ubuntu AWS server

[raw]

Installing composer to an ubuntu AWS server is as simple as:

curl -s http://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer.phar

And if you want to make your life easier:

alias composer='/usr/local/bin/composer.phar'

Aaaand..done. You got to love composer.

[/raw]

How to code a select tag with different value and key for PFBC

i have been checking out the documentation for PFBC trying to find out how I could have my select tag have a different value from it’s key/name in effect being able ot have this

<option value="foo">bar</option>

Normally select is written like that

$form->addElement(new Element_Select("My Select:", "MySelect", array(
   "Option #1",
   "Option #2",
   "Option #3"
)));

By reading the code of the class I have found out that the functionality is actually there. All that you need to do is to replace the ‘Option’ with ‘key’ => ‘value’.
If you are fetching database results or you have a somehow dynamic array this is the structure the array should have.

array(3) {
  ["value1"]=>
  string(19) "Dimitris"
  ["value2"]=>
  string(12) "Janet"
  ["value3"]=>
  string(7) "Yiannis"
}

And this is the format of the select call when you use an array.

$form->addElement(new PFBC\Element\Select("LABEL", "SELECTID", $array ));

I hope this helps if you have any questions let me know.

Zend Framework and mysql_real_escape_string(): Why doesn’t it work?

I had that question asked plenty of times from developers and I just wanted to give a simple clarification and solution.

mysql_real_escape_string() needs a connection to the database using mysql_connecT(). If you are using PDO or mysqli to connect to your database there is no way for mysql_real_escape_string() to find the connection. This is the reason it will not work and prompt you with an error.

There are several ways to fix that.

  • Create a dummy mysql_connect() which will only be used for that. This is not the best solution but it will work.
  • Use $db->QuoteInto(), where $db the object holding your PDO/mysqli connection. This is a ZF function
  • Create your own simple function that will handle XSS injections. (example below)
  • Use $db->quote(), which is the PDO alternative see PDO::quote();

Example of function:


function mres($value) {
$search = array("\x00", "\n", "\r", "\\", "'", "\"", "\x1a");    
$replace = array("\\x00", "\\n", "\\r", "\\\\" ,"\'", "\\\"", "\\\x1a"); 
return str_replace($search, $replace, $value);
}

I really hope that this helps.

If you have found this article useful, do let me know – leave a comment!