Zend : Quick start
Now that we have basic understanding of how zend work. Lets have a quick start with Zend by creating Zend helloworld application.go to command prompt in windows and go to your project directory
that is xampp/htdocs/ if you are using Xampp and c:/wamp/www/ if you are using Wamp
create project by typing
zf create project helloworld
zend will create all the necessary files and folder for your project which look like this;
now go to browser and type the address
localhost/helloworld/public/
you will see the default page of that zend created for you;
Open your project in your favourite text editor, I am using Zend Studio (http://www.zend.com/en/products/studio)
When we first open our project in the browser we see a default page, thats what zend has created for us we have to remove this and add our own code. To do this go to your project helloworld/application/views/scripts/index/index.phtml
open index.phtml in the editor and remove all the code that it contain. than type the following code
now open your browser and type localhost/helloworld/public/ you will see;
Congratulations you have your first changes to the view;
now lets go the Controller and have some changes in it. as we kow that Controller is where the logic of the whole program goes. Every controller has actions and every action is some how related to the view. for example controller/indexController.php has an Action called indexAction() that is related to the view index/index.phtml. if we have another action in indexController named userAction() our view will be also called user.phtml.
now lets pass some values from indexAction() to index.phtml.
go to indexAction() in indexController.php and type the following
now we have assign some values to the variables and pass them to the views. Next we access them in the view and print them as we want. So go to index.phtml and type the following;
now in browser localhost/helloworld/public you will see;
there is no change is the output but this time we pass values from controller to the view.
the values were stored in two variables and than passed into the view. there we print the values.
No comments:
Post a Comment