Zend Framework Application Progress

Tonight's programming lessons included

  • Removing Decorators (dt, dd HTML tags) from Zend_Form_Element_Hidden types. There are several Decorators by using removeDecorator
        $addressid = new Zend_Form_Element_Hidden('addressid');
        $addressid->setAttrib('id', 'form-addressid')
                  ->removeDecorator('HtmlTag')
                  ->removeDecorator('Label');
     
  • Escaping output (removing slashes i.e. O'reilly would be stored in the DB as O\'reilly). We want to just show O'reilly to the visitor.
    Normally in the view you would just enter
        $this->escape($data);
     

    But, I was using a View Helper so I needed to add some special sauce to the view helper to get it to know how to escape.

        class Zend_View_Helper_AddressHtml {
     
            public $view;
     
            public function addressHtml($data) {
                $this->view->escape($data['street']);
     
            }
     
            // This will set the view variable so you can use it above
            public function setView(Zend_View_Interface $view)
            {
                $this->view = $view;
            }
     
        }
     

    Also, to alter the default way to strip out slashes you would use the  init() method in the controller

        public function init() {
          $this->view->setEscape('stripslashes');
        }
     

    Credits:
    Matthew Weier O'Phinney
    ZF Forums

  • Force Zend_DB Query to return an object instead of a select
          $db->setFetchMode(Zend_db::FETCH_OBJ);
     

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal5>, <drupal6>, <javascript>, <php>, <sql>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options