Zend_Form Introduction, part 1
February 4th, 2009This screencast ran a little long, and unfortunately I’ll have to post the rest next week. We start with creating a DTO (Data Transfer Object) that will house our data as we pass it from the Controller, to the form and then back to the view. Zend_Form is used for validation and rendering.
enjoy!

Great tutorials u have here! keep it up.
hi, in PHP/Zend Framework are variables passed and set byref or byval?
eg. when u do a
$this->view->item = $this->session->item
I think we’re passing by value here (making a copy), so watch out! Generally, I prefer this approach unless memory is an issue, so that the “commit” to session is handled in one location.
i am wondering why now we have public functions. we used to have just
function someName() {
…
}
in say Controller classes. is public required? if we dont specify public/private/protected it will be public right?
also i noticed we used $this->name without declaring it say protected $name 1st. this is ok?
PHP is a language that has a lot of old non-OO baggage lying around. If you don’t declare something as “public or private”, it will default to a public function (which I think is a bad move since it inhibits encapsulation). I might have been a little sloppy in the tutorial as I was trying to run through the material.
Same thing with $this->name, you don’t need to declare your variables in PHP before you use them, even if they’re class variables. In production, this is obviously a bad practice! Thanks for mentioning it!
Fatal error: Class ‘App_ItemDto’ not found.
Maybe it’s need to set Loader namespace?
Hey,
I am trying to do what you did,I copied the code and how it works for you?You didn’t require the itemDto.php file..
Fatal error: Class ‘App_itemDto’ not found in D:\Applications\wamp\www\zendFrameworkLearning\application\controllers\ItemController.php on line 17
This the error the i am getting
You’ll have to register the App_ namespace in the Bootstrap.php file for it to work
protected function _initAutoloaders()
{
$this->getApplication()->setAutoloaderNamespaces(array(‘App_’));
return $this;
and in application.ini
includePaths.library = “../library/”
If you use Doctrine and get the strange error:
Fatal error: spl_autoload() [function.spl-autoload]: Class Doctrine_Event could not be loaded in …..
you’ll have to add Zend_Session::writeClose(true);
at the end of your main index.php file
ref:
http://stackoverflow.com/questions/1364750/opcode-apc-xcache-zend-doctri
I modified my Bootstrap file and i no longer have the Fatal error.
But i have no data being displayed. If i comment if($item instanceof App_ItemDto) then i get the notice.
Notice: Trying to get property of non-object in C:\wamp\www\quickstart\application\views\scripts\item\index.phtml on line 14
Hello! At first, thanks a lot for your work!!! Great tuts on the web.
At second – I’ve got a question:
why we are calling $this->addElements in the ItemEditor, and at the same time writing $this->name (or other: description, id).
By writing $this->name we’ve already added this element to the form, or not?
hi Jon, I have a question, i have created a directory in application folder “forms” and in that file I have created a file “Elements.php”, which is a class file.
code goes like this:
<?php
class Forms_Elements extends Zend_Form
{
//all the code
}
————-
now when I call this file, in my action scripts,
code goes like this:
function xx(){
$form = new Zend_Form();
$loudbiteElements = new Forms_Elements();
—- it throws an error Forms_Elements not found in controller.
when I modify it to
function xx(){
$form = new Zend_Form();
require"..application/forms/Elements.php"
$loudbiteElements = new Forms_Elements();
It works normally.
I have initialized zend autoloader in public/index.php
What should I do to make the class load directly, without using [require], in awesome Zend way??