Category Archives: Zend Framework

How to disable layout for some controller

There are some case we need call controller(action)-view with out Zend Layout (Layout.phtml)

In that case, add this line to your action.

Posted in Tech Note, Zend Framework | Leave a comment

Error message for ‘Resource matching “view” not found’

Error Message ::

Fatal error: Uncaught exception ‘Zend_Application_Bootstrap_Exception’ with message ‘Resource matching “view” not found’ in /var/www/vhosts/zend/library/Zend/Application/Bootstrap/BootstrapAbstract.php:694 Stack trace: #0 /var/www/vhosts/zend/library/Zend/Application/Bootstrap/BootstrapAbstract.php(629): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource(‘view’) #1 /var/www/vhosts/zend/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(‘view’) #2 /var/www/vhosts/zend/application/Bootstrap.php(8): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap(‘view’) #3 /var/www/vhosts/zend/library/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initViewSetting() #4 /var/www/vhosts/zend/library/Zend/Application/Bootstrap/BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource(‘viewsetting’) #5 /var/www/vhosts/zend/library/Zend/Application/Bootstrap/BootstrapAbstract.php(586): Zend_Application_Boot in /var/www/vhosts/zend/library/Zend/Application/Bootstrap/BootstrapAbstract.php on line 694


resources.view[] = ""

into application.ini file.

Posted in Error Note, Tech Note, Zend Framework | Leave a comment

Zend Framework, Create modules!

Create Module

[root@testLinux bin]# ./ create module admin

Creating the following module and artifacts:
Added a key for path module directory to the application.ini file
Updating project profile ‘/var/www/vhosts/zend/.zfproject.xml’

Create Controller

[root@testLinux bin]# ./ create controller index index-action-included=1 admin

Note: PHPUnit is required in order to generate controller test stubs.
Note: The canonical controller name that is used with other providers is “Index”; not “index” as supplied
Creating a controller at /var/www/vhosts/zend/application/modules/admin/controllers/IndexController.php
Creating an index action method in controller Index
Creating a view script for the index action method at /var/www/vhosts/zend/application/modules/admin/views/scripts/index/index.phtml
Updating project profile ‘/var/www/vhosts/zend/.zfproject.xml’

Wow, Zend Framework is very nice. It is better than I thought.

Posted in Tech Note, Zend Framework | Tagged , | Leave a comment

Play with Zend Framework Model

I will make a ultra simple GuestBoard with Zend Framework.

(This is just for having taste the Zend Model ^^)

Firstly, create database and table

CREATE TABLE `guestBoard` (
`name` VARCHAR( 100 ) NOT NULL ,
`note` TEXT NOT NULL ,
PRIMARY KEY ( `id` )
INSERT INTO `guestBoard` (`name`,`note`,`date`)
(‘Zend’,’Welcome to Zend World!’,now()),
(‘Codeigniter’,’I am the Best!’,now()),
(‘Symfony’,’Do not forget me!’,now())

Create Zend DbTable

[root@testLinux bin]# ./ create db-table GuestBoard guestBoard

Creating a DbTable at /var/www/vhosts/zend/application/models/DbTable/GuestBoard.php
Updating project profile ‘/var/www/vhosts/zend/.zfproject.xml’

Modify Model File

We just created /application/models/DbTable/GuestBoard.php file.

We need to modify the file to Select, Insert, Update and Delete.

Open GuestBoard.php and modify like this,

class Application_Model_DbTable_GuestBoard extends Zend_Db_Table_Abstract

    protected $_name = 'guestBoard'; //Table Name

	public function getGuestBoard($id){
		$id = (int)$id;
		$row = $this->fetchRow('id = '.$id);
			throw new Exception("Could not find row $id");
		return $row->toArray();

	public function setGuestBoard($name,$note){
		$data = array(
			"name" => $name,
			"note" => $note,
			"date" => new Zend_db_Expr("Now()"));

	public function updateGuestBoard($id,$name,$note){
		$data = array(
			"name" => $name,
			"note" => $note);
		$this->update($data, 'id = '.$id);

	public function deleteGuestBoard($id){
		$this->delete('id = '.(int)$id);

Listing GuestBoard

Modify IndexAction in /application/controllers/indexController.php

public function indexAction(){
	$guestBoard = new Application_Model_DbTable_GuestBoard();
	$select = $guestBoard->select()->order('id DESC');
	$this->view->guestBoard = $guestBoard->fetchAll($select);

Modify View File in /application/views/scripts/index/index.phtml

Create (Zend) Form for Writing GuestBoard

Zend Form will create a form and validate the inputs.

[root@testLinux bin]# ./ create form GuestBoard

Creating a form at /var/www/vhosts/zend/application/forms/GuestBoard.php
Updating project profile ‘/var/www/vhosts/zend/.zfproject.xml’

It created /application/forms/GuestBoard.php

Modify Form

class Application_Form_GuestBoard extends Zend_Form
    public function init()
        /* Form Elements & Other Definitions Here ... */

        $id = new Zend_Form_Element_Hidden('id');

        $name = new Zend_Form_Element_Text("name");
        $name -> setLabel("Name")
             -> setRequired(true)
             -> addFilter("StripTags")
             -> addFilter("StringTrim")
             -> addValidator("NotEmpty");

        $note = new Zend_Form_Element_Textarea("note");
        $note -> setLabel("Message")
             -> setAttrib('cols','20')
             -> setAttrib('rows','4')
             -> setRequired(true)
             -> addFilter("StringTrim")
             -> addValidator("NotEmpty");

        $submit = new Zend_Form_Element_Submit("submit");


Writing new GuestBoard

Add Action to controller (application/controllers/indexController.php)

public function addAction(){
	$form = new Application_Form_GuestBoard();
	$this->view->form = $form;

		$formData = $this->getRequest()->getPost();
			$name = $form->getValue("name");
			$note = $form->getValue("note");
			$guestBoard = new Application_Model_DbTable_GuestBoard();


Create View

Create new (/application/views/index/)add.phtml file

echo $this->form;

Update GuestBoard

Add action to controller

public function editAction(){
	$form = new Application_Form_GuestBoard();
	$this->view->form= $form;

		$formData = $this->getRequest()->getPost();
			$id = (int)$form->getValue('id');
			$name = $form->getValue('name');
			$note = $form->getValue('note');

			$guestBoard = new Application_Model_DbTable_GuestBoard();

		$id = $this->_getParam('id',0);
		if($id > 0){
			$guestBoard = new Application_Model_DbTable_GuestBoard();

Create Edit View File (edit.phtml)

echo $this->form;

Delete GuestBoard

Add action into controller

public function deleteGuestBoard($id){
	$this->delete('id = '.(int)$id);

Make view ( I believe I don’t have to explain how to build view for delete :) )

Posted in Tech Note, Zend Framework | Tagged , , | Leave a comment

Say “Hello, World” with Zend Framework


class IndexController extends Zend_Controller_Action

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

    public function indexAction()
        // action body
	// pass message to VIEW
        $this->view->message = "Hello, World!";



<?php echo $this->message; ?>

OUTPUT : Hello, World!

Set up layout

# zf enable layout

Layouts have been enabled, and a default layout created at
A layout entry has been added to the application config file.

Now layouts folder has been created.

let’s modify it.

open application/layouts/scripts/layout.phtml

and type doctype and meta tags.


<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">

<?php echo $this->layout()->content; ?>
Posted in Tech Note, Zend Framework | Tagged , | Leave a comment

How to install Zend Framework

Let’s taste Zend Framework! (I hope it is yammy ^^)

Firstly, installing Zend Framework.

1. Download Zend Framework latest version

(I download to my computer (windows) first and I will upload files to my server by FTP)

2. Upload Zend Framework to your server.

Extract downloaded file, we can see the bin and library folder. We need 2 folders to install Zend framework.

Upload bin and library folder to your server.

(In my case : /var/www/vhosts/zend)

If you are using WAMP, just replace to your right folder :)

3. Install Zend Framework

zend/bin# ./ create project

(For Windows, using zf.bat. Ex) c:/wamp/zend> zf.bat create project)

output : -bash: ./ Permission denied

(Are you kidding me? I am a ROOT and your MASTER dude~)

Hmm, let’s change file permission @.@;

zend/bin# chmod og=rwxr zf.*

and try again,

zend/bin# ./ create project

Please provide a value for $path

Type right path for Zend project,

zf> /var/www/vhosts/zend

Creating project at /var/www/vhosts/zendNote: This command created a web project, for more information setting up your VHOST, please see docs/READMETesting Note: PHPUnit was not found in your include_path, therefore no testing actions will be created.

ioi, it created. now you can see the application,docs,public,tests folder in your Zend folder.

Try to open the Zend project with your browser!


4. Symlinking Zend libarary into our libarary

Goto your libaray and linking it


# cd /usr/lib

# ln -s /var/www/vhosts/zend/libaray/Zend

5. Set Alias zf and for later

alias zf = /zend_path/bin/


# alias zf = /var/www/vhsosts/zend/bin/

For test,

# zf show version

OUTPUT : Zend Framework Version: 1.11.11

Finally, update virtual host for Zend project

<VirtualHost *:80>
    ServerAdmin root@localhost
    DocumentRoot /var/www/vhosts/zend/public
    SetEnv APPLICATION_ENV "development"
    ErrorLog logs/zend_error_log
    <Directory /var/www/vhosts/zend/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all

Now,we can open Zend index page without /public in URL :)

Posted in Tech Note, Zend Framework | Tagged , , | 1 Comment