Zend Framework Tutorial
|
|
|
Click to rate: |
|
|
|
1,076 votes / avg. rating 33.42%
|
|
Zend_ViewZend_View is a class that helps you organize your view logic. It is template-system agnostic, and for the sake of simplicity, I don't use a template system in this tutorial. You're free to use one if you prefer.
Keep in mind that all incoming requests are now handled by the front controller. Therefore, the framework of the application already exists, and further additions must conform to it. In order to demonstrate a very basic use of Zend_View, change the code in IndexController.php as follows:
Create a file called example.php in the views directory:
<html>
<head>
<title>This Is an Example</title>
</head>
<body>
<p>This is an example.</p>
</body>
</html>
Now, when you request your web site's root resource, you should see the contents of example.php. This isn't very useful yet, but keep in mind that you're working toward a very structured and organized way to develop web applications.In order to make the use of Zend_View a bit clearer, modify your template (example.php) to include some data:
<html>
<head>
<title><?php echo $this-> escape($this-> title); ?></title>
</head>
<body>
<?php echo $this-> escape($this-> body); ?>
</body>
</html>
Two additional features have been added. The $this->escape() method must be used on all output. Even if you create the output yourself, which is going to be the case in this example, escaping all output is a very good habit that can help you prevent cross-site scripting (XSS) vulnerabilities by default.The $this->title and $this->body properties exist to demonstrate dynamic data. These should be defined in the controller, so modify IndexController.php to assign them:
Now you should see these values being used by the template when you again visit your web site's root directory. The reason you use $this in the template is that it is executed within the scope of the Zend_View instance.Keep in mind that example.php is just an ordinary PHP script, so you can do anything you want. Just try to be disciplined enough to limit your use of templates to only what is required to display data. Your controller (or a module to which the controller dispatches) should handle all of your business logic. I want to make one final note about Zend_View before continuing. Instantiating the $view object within each method of the controller requires a lot of extra typing, and our primary goal is to make it easier to quickly develop web applications. It's also a hassle to call setScriptPath() in each case if all of the templates reside in a single directory. Luckily, the Zend class includes a registry that helps you eliminate this overhead. You can store your $view object in the registry by using the register() method:
<?php
Zend::register('view', $view);
?>
To retrieve it, use the registry() method:
<?php
$view = Zend::registry('view');
?>
From this point forward, this tutorial uses the registry.
 |
|
 |
|
Tags:
test, php, dd, tutorial, anup uk, shiflet, shiflett, zend, framework, web, site, anirudha, fdffffffffffffff, hello world, httpwwwgooglecom, kjkljlkj, asasas, vinod, chilli, shiflettasshat, mama, papa, chuckoo, sathishan, nithyan, ashokan, unni, divya, pradeep, abcphp, zde, jayesh jose, harro, ronnie, sample, oui, lebicheur, controller, error, d, kontrola, omg lol, 5, 46457, dfsdfdsf, sdfsdf, asd, crazy, booga, should tags be allowed to be added like this, no i dont think so the tags should be extracted from content, dont allow users to add tags or youll see the results, tags are the root of all evil, thi is, cvcxv, ioncube, zend framework, you already see the results, has not printable version, user created tags how lame, pet the monkey, shoutmouthcom, maybe only registered users should be able to add tags, adding another worthless tag to hammer in the points made earlier, this is only way to add new tag, didip is a complete bonehead, rapdwordpresscom, trke olmayan dkman, turkce olmayan dokumanlar, prova, anytagiwant, bump, wtf, transformers more than meets the eye, this seems like a really bad idea for some reason even though the implementation is reasonably cool, bullshitbingo, fukoka, h, lol, if it has tags on it it must be web20 and therefore cool, ooh look ajax, mike was here, gfgf, doogii, kkkk, annoying, prueba, hjkhklhkjhkjhjk, hi i want to have my own tag here too, oo, what an odd idea to have your own tags for unregistered users ajax, my tag too , xminds, soooo bad that everyone can add tags unmanaged , spam , w00000000t, o0, bottledpuppiesforsalecom, ciao mondo, lollerskates, user added tagshow lame, i agree with what other people are saying guests shouldnt be allowed to add tags, i have a penis, fala serio what a bad idea , cccccc, im2combr, a hrefhttpwwwim2combrcriao de sitesa, wow, good, beep, chick, bleep, stix, mix, fix, this, jesuswillsaverockstarstoo, loldongs, i like it, this is dumb, anyone can tag any article go to my portsite bitchescom, testitest, oh nos its a tarp, hmmm, lets try, what, someone really ought to clean up these tags its a waste of space and an eyesore
Tags Help
Tags are keywords associated with a web page that help classifying information. You can find a good explanation here.
To add one or more tags to this page, simply enter them below (separate them with a comma) and hit enter or click on the "Go" button.
|
|
 |
|
 |
|
Index
|