Zend Framework 1.12.3, part 2

In this post You find out how create new controller and action to it.

Beginn with create your project, its name may be MyDog. In part 2 I described how create the project in Netbeans.

Go to controllers node and right click on IndexController.php node.
In delete window select checkbox Safely delete and click on Refactor button.
From the list of controllers disappear index controller.
In node views/scripts right click on index folder and select Delete element on the menu list.
Click on Yes button in Confirm Object Deletion window.
This is structure applictation after deleted files:
Now You must create controller. Name it as animals. So right click on project name and choose Zend->Run Command.
You view window in which write in Filter field: create controller, and in Parameters field name of controller: animals. Bottom You see in command field all zend command.
The same command You may either run in console:
zf create controller animals
Run this command clicking on Run button in the window.
In tree of project, You may see AnimalsController.php file in controllers folder and new folder in view/scripts folder with index.phtml file.
Ok. Now You want to create new action with describe name for this controller.
First You must delete this old index action.
Double click on AnimalsController.php and in editor delete indexAction method.
Save this file.
And now delete file index.phtml from scripts/animals node. Right click on this file and choose Delete.
In dialog window click on OK button.
It is node after deleting index.phtml file:
Now create new action: describe. Click right on project node and run Zend command(Zend->Run command). In window in Filter field write: create action and in Parameters field write: describe animalsdescribe is action’s name and animals is controller’s name for this action).
Click on Run button that run this command.
In script/animals node You may see desribe.phtml file.
And in AnimalsController.php file You may see new method: describeAction.
Now copy into describe.phtml file this code:



My dog


My dog




and save this file.

Now configure run path. Right click on project node and choose SetConfiguration->Customize.

In Project Properties window in Project URL field add on end the path public folder.

Click OK button.

Double click on application.ini file in application/configs node.

In application.ini file write two lines:

resources.frontController.defaultControllerName = "animals"
resources.frontController.defaultAction = "describe"

These writed lines will on running default controller and default action with these names.

And You may run application click on green icon in top tools menu.