Thursday, February 14, 2013

How to format JSON on the command line

Also known as pretty print.

echo myFile.json | python -mjson.tool

Tuesday, February 12, 2013

Why do I get SplFileInfo::getMTime()... errors in symfony2?

The error, in the browser, might look like this:

SplFileInfo::getMTime() [<a href='splfileinfo.getmtime'>splfileinfo.getmtime</a>]: stat failed for /var/www/html/Symfony/src/Srb/AnthonyBundle/Controller/.#DefaultController.php

If you are using emacs, make sure you save off all files.  If you don't, you might have a # file around, and symfony gets confused.

Install symfony2 and doctrine using composer

1A) Download composer, which will download the composer.phar file which can be kept anywhere:

cd /path/to/composer/install/dir
curl -s https://getcomposer.org/installer | php

1B) Install symfony:

cd /path/to/composer/install/dir
php composer.phar create-project symfony/framework-standard-edition /path/to/webroot/Symfony 2.1.x-dev

2) Check the configuration

Go to http://localhost/Symfony/web/config.php

3) Configure the database

Edit the /path/to/webroot/Symfony/app/config/parameters.yml file

4A) If you already have the database table created, make sure that the primary key is named id.

4B) If you already have the database table created, you can skip to creating an entity class:

php app/console doctrine:generate:entity --entity "MySpecificBundle:Things" --fields="id:int(11) price:float"

5) Edit the src/.../Controller/DefaultController.php file to do something interesting with the database table.

For example:

$row = $this->getDoctrine()
  ->getRepository('MySpecificBundle:Things')
  ->find($name);

if (!$row)
  {
  throw $this->createNotFoundException('No row found for id: '.$name);
  }

$otherVariable = $row->getOtherVariable();

return array('name' => $otherVaraible);

6) Open your browser to http://localhost/Symfony/web/app_dev.php/hello/1 to view the row

7) To create a CRUD scaffold, perform the following command:

php app/console doctrine:generate:crud --entity="MySpecificBundle:Things"

Then open your browser to http://localhost/Symfony/web/app_dev.php/things


Friday, February 8, 2013

Install Symfony2 and propel using composer

1A) Download composer, which will download the composer.phar file which can be kept anywhere:

cd /path/to/composer/install/dir
curl -s https://getcomposer.org/installer | php

1B) Install symfony:

cd /path/to/composer/install/dir
php composer.phar create-project symfony/framework-standard-edition /path/to/webroot/Symfony 2.1.x-dev

_____________________

2) To optionally install propel:

2A) Configure composer.json file

  cd /path/to/webroot/Symfony

  Open /path/to/webroot/Symfony/composer.json in a text editor
  Add in the following line:


 "require": {
        ... ,
        "propel/propel-bundle": "1.1.*"
    },

2B) Download and install propel:

cd /path/to/webroot/Symfony
php /path/to/composer/install/dir/composer.phar update

After this step, you'll need to manually register the bundle in the AppKernel.php file.  See the following page for how to do that: http://propelorm.org/cookbook/symfony2/working-with-symfony2.html#configuration (Search for "The second step is to register this bundle in the AppKernel class:") (Note that I had to add the first configuration on that page, even though I was using Composer")

After that, you'll need to "configure the bundle": http://propelorm.org/cookbook/symfony2/working-with-symfony2.html#configuration Note: I had to comment out or delete the doctrine: block, otherwise symfony would get confused and thought I was using doctrine.

Wednesday, February 6, 2013

How to get HP Color LaserJet 2605dn to print color

I've had a problem getting my HP Color LaserJet 2605dn printer to print color on my Windows 7 64-bit machine, but it's working now.  I had to use the Universal Print Driver (UPD), and in the Control Panel (Control Panel\All Control Panel Items\Devices and Printers), right click on the printer, go to Printer Properties > Device Settings > Device Type (way at the bottom), and change "Auto Detect" to "Color".  You should now be able to print color.