Zend Framework 1.12.3, part 2 – creating controller and view

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.

b01

Go to controllers node and right click on IndexController.php node.
b02In delete window select checkbox Safely delete and click on Refactor button.
b03From the list of controllers disappear index controller.
In node views/scripts right click on index folder and select Delete element on the menu list.
b04Click on Yes button in Confirm Object Deletion window.
b05This is structure applictation after deleted files:
b06Now You must create controller. Name it as animals. So right click on project name and choose Zend->Run Command.
b07You 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.
b08In 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.
b10Save this file.
And now delete file index.phtml from scripts/animals node. Right click on this file and choose Delete.
b11In dialog window click on OK button.
b12It is node after deleting index.phtml file:
b13Now 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.
b14In script/animals node You may see desribe.phtml file.
b15And in AnimalsController.php file You may see new method: describeAction.
b16Now copy into describe.phtml file this code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>My dog</title>
</head>
<body>
<h1>My dog</h1>
</body>
</html>

and save this file.

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

b17

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

b18

Click OK button.

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

b19

In application.ini file write two lines:

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

b20

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.

b21

 

 

 

 

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.