Tweet about this on TwitterShare on FacebookShare on Google+Share on StumbleUponShare on TumblrShare on RedditPin on PinterestEmail this to someone
http://commons.wikimedia.org/wiki/File:PHP-logo.svg

http://commons.wikimedia.org/wiki/File:PHP-logo.svg

If you have read my previous post (How to use Linq in PHP – Part 01), I hope you are waiting for learning about actual usage of this elegant language feature practically. This will be the start of actual coding example and explanation on usage of Yalinqo in PHP.  Currently there are two major releases, but for simplicity and most of you may not have PHP 5.5 (in my case that was the main reason) we will start with YaLinqo version 1.0. Once you get proper understanding and you don’t have any issue in using PHP 5.5 you can easily start using the up to date version of YaLinqo. I assume you have enough PHP experience to know how to install and setup PHP and I will be avoiding explain most of PHP related details due to two main reason. One I think you know enough PHP, second I’m new to PHP and still learning it so I may not be the best person to teach you PHP. I welcome you to tell me if I made any mistakes or improper use of PHP during this series, so we both can benefit.

1. Getting YaLinqo v1.0

You can either clone directly from github if you’re familiar with how to use git and also you have git installed in your local machine, as follows

git clone -b v1.0 https://github.com/Athari/YaLinqo.git

Here note that we specifically requesting the version 1.0 branch. Second option is to go to this link https://github.com/Athari/YaLinqo/tree/v1.0 and from right bottom corner click on “Download Zip” and extract into a directory.

Once cloned or downloaded, you can double check whether you’ve got it by opening the composer.json file on text editor and it should be as follows. You should see the required PHP is version 5.3 or above, if you have cloned/downloaded YaLinqo latest version this PHP version will be 5.5 or above.

Then I renamed the folder to YaLinqo10 in order to make it obvious that I’m using version 1.0 and my test PHP files will be outside of this folder as in following file structure.

--- TestPHPYaLinqo
      |----YaLinqo10
      |----test01.php
      |----utility.php

We will write our code in test01.php file, utility.php file is to have common utility methods that will be used in order write common utility functions.

2. Using YaLinqo in the PHP file

Next thing is to reference YaLinqo in your PHP file and also the utility.php. Open (or create new) test01.php file and include following code.

In Line 4 and Line 5 we include the YaLinqo and utility.php. In Line 7 we refer the Enumerable class of YaLinqo library (this is just to avoid writing complete namespace and class name every where when using Enumerable class).

Open the utility.php and write following code, this is a small function to print output to the console so that we can use it whenever required.

Once again in test01.php file add  following code at the end. Complete file now should like below

Now in command line (windows command prompt or shell in Linux or MacOS) run following command (I hope php executable is already in your PATH). You should get following output.

Now you have setup everything and will start code using YaLinqo from next post onwards.


Posts of this series
How to use Linq in PHP - Part 01
How to use Linq in PHP - Part 02 - Setup
How to use Linq in PHP - Part 03 - Basic Operations
How to use Linq in PHP - Part 04 - Basic Operations
How to use Linq in PHP – Part 05 – Sorting

 

Tweet about this on TwitterShare on FacebookShare on Google+Share on StumbleUponShare on TumblrShare on RedditPin on PinterestEmail this to someone