[ZF2] Zend Framework 2 : Getting Started

Info.Tech, PHP, Web Development, Zend Framework Comments Off on [ZF2] Zend Framework 2 : Getting Started

Since you already installed your PHP composer, next is you will download the Zend Skeleton Application at


Extract or save the files to your apache/httpd public folder. In my case, it was in;

D:\localhost\zend2>cd HelloWorld

 Volume in drive D is WorkFiles
 Volume Serial Number is 3220-C192

 Directory of D:\localhost\zend2\HelloWorld

10/11/2012  04:20 p.m.    <DIR>          .
10/11/2012  04:20 p.m.    <DIR>          ..
10/11/2012  04:20 p.m.                83 .gitignore
10/11/2012  04:20 p.m.                92 .gitmodules
10/11/2012  04:20 p.m.               336 composer.json
10/11/2012  04:20 p.m.           570,295 composer.phar
10/11/2012  04:20 p.m.    <DIR>          config
10/11/2012  04:20 p.m.    <DIR>          data
10/11/2012  04:20 p.m.             1,812 init_autoloader.php
10/11/2012  04:20 p.m.             1,548 LICENSE.txt
10/11/2012  04:20 p.m.    <DIR>          module
10/11/2012  04:20 p.m.    <DIR>          public
10/11/2012  04:20 p.m.             1,753 README.md
10/11/2012  04:20 p.m.    <DIR>          vendor
               7 File(s)        575,919 bytes
               7 Dir(s)  111,679,717,376 bytes free

The composer.json is the requirement for the PHP composer.phar to update and install components/packages for the Zend Framework 2 (ZF2).

The next you need to do is to self-update and install. Follow the command below;

D:\localhost\zend2\HelloWorld>php composer.phar update
This dev build of composer is outdated, please run "composer.phar self-update" to get the latest version.
Loading composer repositories with package information
D:\localhost\zend2\HelloWorld>php composer.phar self-update
Updating to version dea4bdf.
    Downloading: 100%

D:\localhost\zend2\HelloWorld>php composer.phar install
Loading composer repositories with package information
Installing dependencies
  - Installing zendframework/zendframework (2.0.6)
    Downloading: 100%
4123 File(s) copied
5 File(s) copied
6 File(s) copied
1797 File(s) copied
37 File(s) copied
2268 File(s) copied
1 File(s) copied

zendframework/zendframework suggests installing doctrine/common (Doctrine\Common >=2.1 for annotation features)
zendframework/zendframework suggests installing pecl-weakref (Implementation of weak references for Zend\Stdlib\CallbackHandler)
zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf for creating PDF representations of barcodes)
zendframework/zendframework suggests installing zendframework/zendservice-recaptcha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\Form)
Writing lock file
Generating autoload files


That’s should do it… So you can view the installed ZF2 to your browser. It should look like the image below;

Installed Zend Framework 2.0.6

I hope this will help in your pursuance in studying Zend Framework or if you already into ZF but at version 1.x, then this is a good start for the ZF2.

Installing PHP composer.phar

Info.Tech, PHP, Web Development, Zend Framework Comments Off on Installing PHP composer.phar

This guide is installing PHP composer.phar and proceed to ZendFramework 2.x setup/installation.

First, go the your PHP installed directory then cast the command;

cd C:\php\bin
C:\php\bin>php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

At the same working directory, C:\php\bin, create a file named composer.bat and it should contains the following;

SET composerScript=composer.phar
php "%~dp0%composerScript%" %*

Then test it if its working…

  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
Composer version dea4bdf

  [options] command [arguments]

  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v Increase verbosity of messages.
  --version        -V Display this application version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.
  --profile           Display timing and memory usage information
  --working-dir    -d If specified, use the given directory as working directory.

Available commands:
  about            Short information about Composer
  config           Set config options
  create-project   Create new project from a package into given directory.
  depends          Shows which packages depend on the given package
  dump-autoload    Dumps the autoloader
  dumpautoload     Dumps the autoloader
  help             Displays help for a command
  init             Creates a basic composer.json file in current directory.
  install          Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  list             Lists commands
  require          Adds required packages to your composer.json and installs them
  search           Search for packages
  self-update      Updates composer.phar to the latest version.
  selfupdate       Updates composer.phar to the latest version.
  show             Show information about packages
  status           Show a list of locally modified packages
  update           Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate         Validates a composer.json

C:\php>composer.bat -V
Composer version dea4bdf

That’s it… You can now proceed in downloading the Zend Framework or Symfony. The next guide, I will be using Zend Framework 2.x in my case.

Reference: http://getcomposer.org/doc/00-intro.md#installation-windows

Zend Framwork: Accessing Database in different ways

Info.Tech, PHP, Web Development, Zend Framework Comments Off on Zend Framwork: Accessing Database in different ways

Assuming I declared some variables in application.ini named webbyConfig and initialized in Bootstrap.php;

$config = Zend_Registry::get('webbyConfig');
$this->_db = new Zend_Db_Adapter_Pdo_Mysql(array(
        'host'     => $config['db_host'],
        'username' => $config['db_user'],
        'password' => $config['db_passwd'],
        'dbname'   => $config['db_name'],


$sql = 'SELECT a.col1,b.col2 FROM tableA AS a, tableB AS b WHERE a.id = b.id AND a.id = 1';

$stmt = $this->_db->query($sql);

and this is another way accessing the db…

$sql = 'SELECT a.col1,b.col2 FROM tableA AS a, tableB AS b WHERE a.id = b.id AND a.id = 1';

$db = Zend_Db_Table::getDefaultAdapter();

$stmt = $db->query($sql);

That’s what I know so far… I think there’s more… still exploring ZF. 🙂

Zend Framework: Upload File Demo

Info.Tech, PHP, Web Development, Zend Framework 1 Comment »

I’ve came across in uploading file using Zend Framework (ZF)… Since ZF is new to me, its like I’m studying PHP just like when I started, I have to memorize the predefined variables and functions but in ZF, its their classes, defined variables and its functions. Here’s my codes though its not perfect but its working.


class IndexController extends Zend_Controller_Action

    public function init()
        /* Initialize action controller here */

    public function indexAction()
        // action body
        $form = new Application_Form_Upload();

		private function getFileExtension($filename)
			$fext_tmp = explode('.',$filename);
			return $fext_tmp[(count($fext_tmp) - 1)];

		public function uploadAction()
			$dest_dir = "uploads/";

			/* Uploading Document File on Server */
			$upload = new Zend_File_Transfer_Adapter_Http();
						 ->addValidator('Count', false, 1)
						 ->addValidator('Size', false, 1048576)
						 ->addValidator('Extension', false, 'jpg,png,gif,pdf');
			$files = $upload->getFileInfo();

			// debug mode [start]
			echo '<hr />
			echo '	</pre>
						<hr />';
			// debug mode [end]

				// upload received file(s)
			catch (Zend_File_Transfer_Exception $e)

			$mime_type = $upload->getMimeType('doc_path');
			$fname = $upload->getFileName('doc_path');
			$size = $upload->getFileSize('doc_path');
			$file_ext = $this->getFileExtension($fname);
			$new_file = $dest_dir.md5(mktime()).'.'.$file_ext;

			$filterFileRename = new Zend_Filter_File_Rename(
					'target' => $new_file, 'overwrite' => true


			if (file_exists($new_file))
				$request = $this->getRequest();
				$caption = $request->getParam('caption');

				$html = 'Orig Filename: '.$fname.'<br />';
				$html .= 'New Filename: '.$new_file.'<br />';
				$html .= 'File Size: '.$size.'<br />';
				$html .= 'Mime Type: '.$mime_type.'<br />';
				$html .= 'Caption: '.$caption.'<br />';
				$html = 'Unable to upload the file!';



Below is the source file of whole project in Zend Framework for you to test it out… Enjoy!

Source Code: ZF Upload File Demo (1401)

Zend Framework: changing public to public_html for CPanel

PHP, Web Development, Zend Framework 1 Comment »

In Zend Framework, the public files are located at public folder, but CPanel are located at public_html. What you will do is create a symlink.

ln -s public public_html

then this structure will work:

    public_html # this is actually a symlink pointing to public

That’s it… 🙂


Reference: http://stackoverflow.com/questions/3903127/hosting-php-zend-framework-application-on-shared-cpanel-server

Thanks to: prodigitalson


WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in