Sunday, 13 September 2015

Use Symfony2 to create template/skeleton code

Pre-requisite: A lamp environment, i will be using a vagrant lamp box (scotch-box) i created earlier.

To understand Symfony2 there is nothing better than getting ones hands dirty. We will try to use doctrine to build models, create views using twig and maybe use a dash of frontend magic using backbone or something similar.

For the test project I chose a sales bundle where we will make models for item, item type and sale.

Using symfony2 command line to create a model.

Because i have used vagrant scotch-box to provision my dev environment, i need to first make sure i do vagrant up to start the VM. then i do vagrant ssh this will take me to the ssh


locate where you have symfony installed, in my case it is /var/www/public/sandbox and give the following command:

php app/console generate:bundle

pick a name any name....well not actually, we need to be following coding standards set out in the symfony guide to ensure we name our bundle like this Bundle, so in my case i didn't have a vendor, so i chose a project name in this case it was Test\SandboxBundle, the bundle was named TestSandboxBundle and relevant files were created for me.



I just chose the defaults and had symfony create all it deemed good and wholesome...this will be additionally helpful if we peep under the hood as to what and where things are normally stored.

Now our bundle is created, we can create some models so in the symfony root in my case /var/www/public/sandbox i type the following command in order to generate the entities.

Entities we need: We are attempting to create a pos system, so we will have the following models:

ItemType - Types of item eg. Toys, Bakery, Drinks etc
  Id, Name (string:50) & Description (string: 250)

Item - The item, this will linked with item type
  Id, ItemTypeId (int), Name (string:50), Description (string:250), Price (descimal), Opening Stock (int)

Sale - the actual sale which will link to the item.
  Id, Date (date time), ItemId (int), Quantity(int), CustomerId(int)

Customer - the customer, to make things easier, we will create only 2 customers 1 pos & the other for WEB orders.
  Id(int), Name (string:50), Address (string:250), postcode (string:12)

So we generate these models one by one, the options i have chosen are as follows:

The Entity shortcut name
: TestSandboxBundle:

Configuration format for all (yml, xml, php, or annotation) [annotation]: annotation

Note that the primary key will be added automatically (named
id). When it asks do you want to generate an empty repository class say yes.

You can now start using the generated code!  

                                               





Installing sqlyog on Mac OS X Yosemite

I like to use sqlyog for my work with mysql, but only windows binaries are supplied on the google code site.

Another option is to use sqlyog in wine, so to install wine a simpler option is to use Homebrew (http://brew.sh/).

Installation for homebrew is quite straightforward, however you need to have installed the command line tools with xcode, if not please install that first.

The installation instructions are already on the first page of the homebrew website, so i will not reproduce this, once brew is installed, install wine.

brew install wine

when i tried installing wine, brew asked me to install a dependency and nicely told me to do the following

wine: XQuartz is required to install this formula.
You can install with Homebrew Cask:

  brew install Caskroom/cask/xquartz

so i just did that, once this was completed i could complete installing wine.

Now head over to https://code.google.com/p/sqlyog/wiki/Downloads and install the latest sqlyog, at the time of writing this blog the version was 12.0.9 (SQLyog Community Edition - 12.09 (32-Bit))

Download the installer file, this will be in your Downloads folder. Use terminal and navigate to Downloads folder and install using the following command.

wine SQLyog-12.0.9-0.x86Community.exe

This installed sqlyog on my mac.

Sunday, 6 September 2015

Installing Symfony2

Installation for Symfony was straight forward, using the new symfony installer.

head over to symfony https://symfony.com/download and download the installer, installation instructions are included on the page.

Remember we are using the vagrant box we installed earlier, start vagrant using vagrant up and you should then have a public folder under your scotch-box folder under vagrant.

Install symfony under this folder.


Add behat in Symfony 4

To add behat in Symfony 4 i have generally followed this link https://blog.rafalmuszynski.pl/how-to-configure-behat-with-symfony-4/ How...