Thursday, March 21, 2013

PHP Composer. How to install and use on a portable USB device. ZF2, Doctrine 2 ORM

I am constantly on a move. I don't like to carry laptop or other device. Or even if I do, I would like to switch between devices very easy. I like to have my development stack on a portable USB device. The best is to have it in the cloud. I have separate tutorials about that. But the cloud IDE have very limited console abilities for now. So I have to do some tasks on a local computers with native apps. I am using portable XAMPP (manually installed) and my goal is to work with ZF2 and Doctrine 2 ORM on a portable USB device.


========== Install composer and ZF2  on a portable device ==========

1) Prepare the PATH environment variable

2) Make sure SSL is enabled in PHP
 3) Install the composer in XAMPP/PHP on the USB drive
php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
 4) Make composer global, by creating a bat file
echo @php "%~dp0composer.phar" %*>composer.bat
 5) Check if the composer works
composer -V
 6) How to get help?
composer help
 7) Note: composer doesn't work on devices different from c:
 8) Workaround. Create the project on c:
composer create-project --repository-url="http://packages.zendframework.com" zendframework/skeleton-application c:\projects_composer
 9) Copy the project to the portable drive if you don't want to install more things with composer
 10) Create a virtual host (I prefere to use ports insted of subdomains)
# for my composer tutorial
# don't forget to change /etc/hosts or c:\windows\system32\drivers\etc\hosts
# <VirtualHost *:80>
<VirtualHost *:8081>
    ServerName zf2-tutorial.localhost
    DocumentRoot /projects_composer/zf2-tutorial/public
    SetEnv APPLICATION_ENV "development"
    <Directory /projects_composer/zf2-tutorial/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
# Extra line not mentioned in the tutorial
Require all granted
    </Directory>
</VirtualHost>

 11) We have to change the file hosts on the current computer (I don't like this approach)
127.0.0.1               zf2-tutorial.localhost localhost
 12) For some Apache versions we have to add 1 line more to make it work
 13) Note: If we try to change the path to h:\xampp\php to be able to use php on c: drive, we get error!
 14) (Optional) Alternative method to install ZF2
 15) Note:  Alternative method to install ZF2. We have the same error


=== The steps below just repeat what was described but in greater details ====

16) We run composer from the USB drive but on Windows we are forced to use  a directory on drive c:
THE STEPS BELOW ARE
 17) Install ZF2 using "composer" but in a folder of drive c:
composer create-project --repository-url="http://packages.zendframework.com" zendframework/skeleton-application c:\projects_composer
 18)  As a result of the execution a folder has been created on drive c:
 19) If you have finished move the app to the portable device
 20) Prepare the virtual host
 21) prepare the hosts file
22) The location of the tutorial
 23) Check the application

================= The alternative installation =================

24) The alternative installation
 25) Alternative. Download the zip file of the skeleton app from github
 26) Alternative. Unzip in a folder of drive c: "ZendSkeletonApplication-master"
 27) Alternative. Composer composer self-update -d C:\projects_composer\ZendSkeletonApplication-master
 28) Alternative. Composer install -d C:\projects_composer\ZendSkeletonApplication-master
 29) Alternative. The "composer install .." from the step above was created a lot of files and folders
 30) Alternative. If you have finished using the composer move the created folder to your portable device

=Modules installation. DoctrineModule and DoctrineORMModule installation.=

 31) Find a module you want to install. (DoctrineModule )
 32) Find it in github
 33) read the install instructions. Usually composer is used
 34) composer require doctrine/doctrine-module:0.* -d C:\projects_composer\zf2-tutorial
 35) Add the module to application.config.php
 36) If you have finished with the installation copy the folder with the app to the portable device
 37) Install Doctrine ORM or ODM. composer require doctrine/doctrine-orm-module -d C:\projects_composer\zf2-tutorial
 38) Add the module to the application.config.php
 39) Create a folder (as described in the install instructions) data/DoctrineORMModule/Proxy


Tuesday, March 12, 2013

How to synchronize with the original repo

When you participate in a OSS (Open Source Software) project from time to time you have to synchronize your fork. This is how it is done in Codenvy:


Sunday, March 10, 2013

Create a layout for ZF2 application in Codenvy

In this  step by step tutorial you will learn how to create a ZF2 layout and use it in your actions.

1) Choose  a template.
Note: Or create a template (e.g. in Photoshop etc.)


2) Create a "lyout" folder in your module


3) Upload the html file from the template. Or create the file.


4) (Optional) Rename the file so it makes more sense for you. 


5) (Optional) Create a folder for this template in "public".


6) Upload the resources (e.g. css files etc.)


7) Upload the images.
Note: Choose "text/plain" as MIME type.


8) Correct the urls for the resources used in the HTML file. (in layout folder)


9) Correct the URLs for the images too.


10) Add the layout to your module.config.php. The entire app will be aware.
Note: give a unique name (e.g. "layout/StoyanCheresharov") for the key


11) Add the content placeholder. Whatever comes from the action will be displayed there.


12) Create a new action to use the template. (e.g. changeAction)


13) Create the view script for the new action. (e.g. change.phtml)


14) Add all the changes to the git staging area.(e.g. git add .)


15) Commit the changes (e.g. git commit -m "New layout create and registerd")


16) Push to the development server to see the changes. (e.g. git push zend)


17) Access the action that uses our new template (e.g. /stoyan-cheresharov/change)


18) (Optional Idea) You can send a parameter and use it to change the content etc. of the page


19) (Optional.) Just for fun you can change the key of the new layout and name it "layout/layout".
This way you make it default for all the action in the app.


20) Push the changes to your fork in github.


21) (Optional) Send a pull request to the owner of the original repo.