Laravel 4 Validation in Codeigniter

I decided to convert my Codeigniter application to Laravel 4 but since the code base of my application is pretty stable I decided to used some of Laravel 4′s components inside Codeigniter until my web application is fully Laravel-based apps.

First thing I did was to used Laravel’s Eloquent

Next thing I would like to do is to show how to use Laravel 4′s Validation inside of Codeigniter apps.

So lets get started.

 

Using Eloquent ORM inside Codeigniter

Last time I wrote an article on how you can use Eloquent ORM outside of Laravel 4. This time we are going to integrate Eloquent ORM inside our Codeigniter apps. As most of us know, Laravel used composer for bundles including its database (Illuminate Database). In my application I use Codeigniter Active Record, Datamapper Orm. Now that I create application using Laravel, I want to use Laravel’s Eloquent ORM in my existing Codeigniter application.

Install Composer

The first thing we need to do is to install composer. If you are new to composer you may want to read some article about it here

Create json File

Create file and name it composer.json in the root folder of your Codeigniter application. Since Eloquent ORM only runs on PHP 5.3 or later I assume you use that PHP version. Notice that I add key for autoload then the classmap. Change the path where your eloquent models resides. Dont forget to run $ composer dump-autoload after you created a new Eloquent Model

Install Illuminate Database

Open you terminal (command prompt in Windows) then navigate to you Codeigniter’s root folder then enter the following command:

You should see message something like this:

composer

This will create “vendor” folder in your apps root directory.

Autoload

Add require ‘vendor/autoload.php’; just before the codeigniter bootsrap

Create models and connection files

Create two files and save it in your models directory.

Test it

Fingerprint Redirection

We received a call from a customer very recently, where the issue was that when customer remotes into a system which has an application using Digital Persona SDK installed on the box and tries to run it ,it says fingerprint reader not connected although the reader was connected to the system. Now if the user is directly at the terminal and runs the application, it recognizes the fingerprint reader.The reason for this is that Digital Persona readers do not support USB virtualization (i.e) when we RDP into a box we cannot virtualize USB like we do with printers, but we do support fingerprint data redirection which means we can transfer fingerprint template data on wire.

For example, for one of our Enterprise products online client you can have a citrix server where you can  install the Online client software, have reader plugged into a client machine, RDP into a citrix server, scan finger on the client machine, thus transferring fingerprint image via wire.

To configure Citrix client following are instructions

  1. Locate the DPICACnt.dll file on the Misc\Citrix Support folder on the Online Client CD, and copy it to the folder on the client computer where the Citrix client components are located (that is, or the Program Neighborhood client, the file might be in the Program Files\Citrix\ICA Client folder).
  2. Using the regsvr32.exe program, register the DPICACnt.dll library.
  3. If you have several Citrix clients installed on a computer, repeat steps 1 and 2 for each client

To RDP  below are instructions

    1. On the client, Create a new .reg file and add the following:
    2. Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\DigitalPersona\Policies\Default] “AllowFPRedirect”=dword:00000001 “ForceAuthOnServer”=dword:00000001 “ForbidFPCompression”=dword:00000001

From http://digitalpersonablog.com/devportal/2012/10/11/fingerprint-redirection/

Imagemagick for Windows

I got a lot of problem installing imagemagick for windows!

My project requires me to convert PDF files to jpg to able to view the files into browser of Tablets that we have purchased.

So here is the steps I did:

1. Install the XAMPP 1.8.1 at the time of writing.

2. Install imagemagick 6.8.0-4-Q16-dll

3. Then restart

4. Install image magick extension to php.ini (http://www.peewit.fr/imagick/) I use thread safe.

5. Install the ghostscript. then restart. imagemagick 5.4 does not support relative path http://stackoverflow.com/questions/9954764/imagick-php-5-4-extension-does-not-work-with-relative-paths-windows

6. Happy me :)

 

Some old ref.

http://snipplr.com/view/48513/pdf2jpg–convert-pdf-to-jpg-images-with-imagemagick/

Setting Up Composer PHP Dependencies Manager in Windows

Probably one of the most important principles in Software Engineering is DRY (Don’t Repeat Yourself!), every time you found yourself writing the same code more than once, in a same project, or in different projects then you have to re-think of what you have done. For example, how many times you have wrote authentication system for your projects? Or email class to send emails with PHP? If you’re doing it over and over again, maybe a package management could help you on this.

PHP Packages Dependencies Manager

PHP has PECL and PEAR as repository for extension and code libraries, PECL stands for PHP Extension Community Library, in PECL extensions is written in C language, and can be loaded into PHP to provide additional functionality. What you need to use PECL is administrator rights, C compiler and associated dependencies for those extensions. PEAR is PHP Extension and Application Repository, where in PEAR the extension or libraries is written in PHP. So it could be downloaded and loaded to our PHP code.

PECL and PEAR are great tools, but they are system-wide packages manager, meaning, it’s installed on the system not per project, and not everyone prefer that, at least me. I often just do everything on-the-fly in PHP, whenever I need a PHP library, I will just simply download and include it, and it’s the era of PHP Frameworks, many commons functionalities has been included on the frameworks. But that’s create one big problem, everyone have their own pick on the framework, and each framework has their OWN implementation of providing functionalities with their libraries, that makes switching frameworks not an enjoyable task, we need to re-learn many things.

What is Composer?

Composer exists to overcome the problem mentioned above, composer is a dependencies manager that come in a form of command utilities, composer make it possible to ‘plug and play’ PHP packages across application no matter what frameworks we are using as long as the packages follow the shared format. With composer we can define our project dependencies simply in a ‘composer.json’ file, and later on we can install and update these dependencies automatically.

An example:

1
2
3
"require": {
    "illuminate/blade": "dev-master"
}

This will make composer include ‘blade’ from the vendor `illuminate` in our project, and we can do update to the ‘blade’ package with one command.

Setting Up Composer In Windows

And here comes the main topic, how to set up composer, and this one is specifically written for windows users. At first, I planned to wrote the complete instruction on how to setup composer in windows with the standard way, which including downloading the installer manually and run the install on command prompt, and also how to make the composer can be accessed globally by pre-run a bat script every time we open command prompt, it can be achieved by hacking around with the registry editor, but I found a much better solution, instead of going with all the fuss, we are going to use a really cool installer built by John Stevenson which you can download the composer windows installer and do the install easily. With this installer, you can choose whether you want to install it per project basis or install it globally so you can run the ‘composer’ command everywhere on your projects.

Installing Composer in Per Project Basis

To install composer in windows per project basis, you just need to choose the ‘basic’ option in the installation procedure.

Composer Windows Installer Basic Option

Composer Windows Installer Basic Option

And then you just need to specify the folder, where you want the composer will be installed.

Composer Windows Installer Choose Folder

Composer Windows Installer Choose Folder

And here it is, you can access the composer on the selected folder, and you will need to be able to run ‘php’ via command prompt, and use the composer.phar that has been installed in the folder.

Run Composer Command Per Project Basis

Run Composer Command Per Project Basis

Installing Composer to Use Globally in Every Projects

This is the setup that I prefer, to install the composer globally, that way you can use composer everywhere. And to setup composer in windows globally, just like the previous one, you just need to choose an option, which is ‘global’ option.

Composer Windows Installer Global Option

Composer Windows Installer Global Option

And here you go, open up your command prompt, and you can access composer, as easy as just calling composer.

Run Composer Command Globally

Conclusion

Composer is a great tool for managing packages and dependencies in your projects, let’s hope every packages in PHP will be available in composer soon and I encourage everyone to write their packages in compliance with composer, so that everyone can share their packages no matter what framework we are using. And for your information most of the famous PHP frameworks has started to give their full support to composer, and built their system components as composer packages, you can check out FuelPHP, Laravel 4, and Symfony2. So it’s the end of guide on setting up composer in windows, for UNIX based operating system, you could do this easily via terminal, which has been documented well on the composer site.

Reposted from http://diywebdev.com/setting-up-composer-php-dependencies-manager-in-windows/