So far we have been working with the Action and Views that Zend provide as default. now we have to create our own Action and Views. Views are used as pages in the website and Actions in controller contain the logic of the views. .
Creating Action inside helloworld
inside command prompt go to your project directory and create an action by typing the following command
zf create action {name of action} {name of controller}
as we know that actions are inside controllers so it is essential to give the Controller name
I am creating user action inside indexController.php my command will be;
zf create action user index
i don't have to give the full name of the controller because Zend is smart enough to recognize it
now an action is created inside indexController.php namely userAction().
Creating view for action
Every views is use as a page in website. So every zend view is a page and the logic of the page is inside the Action. in our case our page is user.phtml and the logic of the page goes inside userAction(). now we have to create view for the action. where we can display the data of the action.
To create view just type;
zf create view {name of the controller that contain Action} {name of the action}
in my case i will type;
zf create view index user
now the project have some changes in it;
now we can add code to our views and action. and than access the page inside browser.
let pass an array from userAction() to user.phmtl
first open your indexController.php and inside userAction() type an array like;
and than chage the user.phtml to access the array data as;
now to access our page we have to make some changes to the url
in Zend we access the action of the controller in the url
projectname/public/{name of controller}/{name of action}
in default case it is;
helloworld/public/index/index
meaning the indexController and indexAction
now as we are Accessing the indexController and userAction we will type as our url as;
helloworld/public/index/user
and long behold this is now a new page
now let make some changes to the layout file so that we can access our page from a link
open layout.phtml and make the following changes
we have made these changes so when we click on the HOME we are taken to index/index
and when we click on SERVICES we go to index/user
try this at home
No comments:
Post a Comment