Wednesday, July 29, 2015

Code Highlighting for Blogger

I don't want to change my template. I don't want to pull in the code via JavaScript like gist embedding does. I just want an HTML snippet of formatted code compatible with blogger. Today I'm using hilite.me to format my code. Anyone using anything better?

PHPStorm + xdebug + ScotchBox 2.0

ScotchBox 2.0, by design, does not have xdebug installed. They give the following install instructions:

sudo apt-get install php5-xdebug
sudo service apache2 restart

Which works as far as it goes, but even successfully using PHPStorm's "Web Server Debug Validation", and installing and using the Xdebug bookmarklet, I was not able to get the debugger working.

This post gave me the insight that I needed, so I added the following code to the end of my php.ini (sudo nano /etc/php5/apache2/php.ini).

[xdebug]
zend_extension="/usr/lib/php5/20131226/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_connect_back=on
xdebug.remote_host=192.168.33.10

Restart apache (sudo service apache2 restart), run PHPStorm's "Web Server Debug Validation" again, and Bob's your uncle.

Thanks to Joao Paulo for making it simplier.

Saturday, July 11, 2015

mRemoteNG

Vagrant boxes, linux servers, and SSH session terminals, oh my! To clean up the mess, I installed mRemoteNG, to put the PuTTY sessions in tabs. Still get to keep my custom settings... just have it all boxed up for neatness now. Recommended.

Note that there are a lot of alternatives, and I just don't have time to try them. A quick trip through Wikipedia has an article on programs, and I see a lot of people using SuperPuTTY.

I'll also have to check out KiTTY on some rainy day, but really I have no complaints with PuTTY at the moment. Should I care about KiTTY if I already have PuTTY working nice?

Wednesday, July 08, 2015

Enable the PrestaShop 1.6 Smarty Debug Console

  1. In /config/defines.inc.php, changed _PS_MODE_DEV_ to true.
  2. In /config/smarty.config.inc.php, after the assignment of the $smarty variable, add the following code:
    if (defined('_PS_MODE_DEV_') && _PS_MODE_DEV_)
        $smarty->debugging = true;
  3. In the template (.tpl file) you want to see debug info, add the following line at the very end of the template
    {debug}
  4. In the back office / advanced parameters / performance, click the "Clear Cache" button at the top right.
  5. In the URL that you are testing, add the param SMARTY_DEBUG (e.g. http://ls/index.php?id_product=57&controller=product&SMARTY_DEBUG).
  6. Make sure that you are not getting a pop-up blocked by your browser. Once you allow the popup, you will get your console.

Note that San Binario wrote up an alternative method to get the debug console working which changes the core code, which I wanted to avoid. I didn't try their method... but maybe it works better for you.

Thursday, July 02, 2015

PHPStorm Autocomplete for PrestaShop Classes

Hmmm, doing a find in files for "public static function isInt" to try to find the validation class (or optionally hitting ctrl+N and looking for the ValidateCore class) is not what I want... I want autocomplete for Validate::(I need the "isDecimal" version).

Julien Bourdeau has the solution, PhpStorm-PrestaShop-Autocomplete. Quick install and just works. Thanks, Julien!

Ah! It's "Validate::isFloat".

Wednesday, July 01, 2015

PrestaShop Admin Area Hook Error Reporting

I needed to validate data, report any errors found, and stop the submission of the form while developing a module for the PrestaShop 1.6(.0.14) admin area. However, the documentation was a bit thin on how to do this, and I needed quite a bit of digging before I found what I needed.

I can only tell you 100% for sure that this works for the actionProductUpdate hook, but I imagine it's valid everywhere. Here's a quick snippet to show you the general idea....
 
public function hookActionProductUpdate($params)
{
  if (!Validate::isInt (Tools::getValue('pwr_start')))
  {
    $this->context->controller->errors[] = "Ya screwed up!";
  }
}

There are 3 main things you want to take note of:
  • Use the Validate class to validate your input data
  • Use Tools::getValue instead of directly pulling things from $_GET / $_POST. This does some light purification of the input data.
  • If you want to stop the submit of the form, add the error to the controller's error list. Unfortunately, this is only reported at the top of the form.