Zend_Form Introduction, part 1

February 4th, 2009

This 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!
 

15 Responses to “Zend_Form Introduction, part 1”

  1. iceangel89 says:

    Great tutorials u have here! keep it up.

  2. iceangel89 says:

    hi, in PHP/Zend Framework are variables passed and set byref or byval?

    eg. when u do a

    $this->view->item = $this->session->item

  3. jon says:

    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.

  4. iceangel89 says:

    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?

  5. iceangel89 says:

    also i noticed we used $this->name without declaring it say protected $name 1st. this is ok?

  6. jon says:

    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!

  7. David says:

    Fatal error: Class ‘App_ItemDto’ not found.
    Maybe it’s need to set Loader namespace?

  8. Yosy says:

    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

  9. jon says:

    You’ll have to register the App_ namespace in the Bootstrap.php file for it to work :)

  10. Sil2 says:

    protected function _initAutoloaders()
    {
    $this->getApplication()->setAutoloaderNamespaces(array(‘App_’));
    return $this;

  11. Sil2 says:

    and in application.ini
    includePaths.library = “../library/”

  12. Stéphane says:

    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

  13. shaded says:

    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

  14. BTaller says:

    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?

  15. Joddy Street says:

    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??

Leave a Reply

Desktop RSS feed iPhone + iPod