How to check multi-option Zend Form array values in View

We can get the Multi-option values set in Zend Form  and to compare the values in the view using the following function.
  
   Ex: $multiValues    =    $this->form->getElement('all_roles')->getMultiOptions();
        In the 'all_roles' is the form elememnt name in the Form/

How to add 'default' attribute with url parameter

In the url function first we define the controller, action and parameters. Then we need to add the 'default' attribute or else the url is formed with the existing url in the browser.
 $this->url(array('controller'=>'events','action'=>'view','id'=>1),'default',true);

How to fix the Error 'was not found in hastack'

It's the validator for array elements in the Form and it has default in_array validator.
We can remove that validation using setRegisterInArrayValidator to false
   Ex : $userRoles->setRegisterInArrayValidator(false);

Warning: Select query cannot join with another table

The Zend_Db_Table_Select is  used to constrain and validate so  that it may enforce the criteria for a legal SELECT query. There  may be certain cases where you require the flexibility of the  Zend_Db_Table_Row component and do not require a writable or deletable  row.In such cases you can set 
$select->setIntegrityCheck(false)

How to user WHERE IN clause in Zend Query(Zend_Db_Select)

We don't need to implode the array to use with WHERE.
  $users = array(1,2,3);
  $selectQry    =    $this->db->select()->from(array('FI'=>'TBL_NAME'))
                          ->where('FI.user_id IN (?)',$users);

How to get the base url in Zend form

$view = Zend_Layout::getMvcInstance()->getView();
 $baseUrl    =    $view->baseUrl();

Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'Headlink' was not found in the registry

 If you get the following error or error similar to that, it causes the issue with the function name that you have used.
     
       Ex; $this->headlink('pathToFile'); It's not correct and shows the error.
       It must be $this->headLink('pathToFile'); ie 'L' must be capital letter.

How to set a Form attribute from controller


   If we have a form used for different purpose and in one of the action you want to set a particular attribute to form object. Then you can do that by setting the attribute value from the controller action page.
   Ex:
     public function addAction()
     {
         $form    =    new Form_User();
         $updateUser=    $form->addUser();
         $updateUser->role->setAttrib('disabled','true');
     }

How to set SMTP mail using Zend Framework

1. First you have to download the Zend Framework library.
      Then place it somewhere in the server with name like library and set the include_path to your working php page
      Ex: set_include_path(get_include_path().PATH_SEPARATOR.realpath(realpath(dirname(__FILE__)).'/library'));
   2. Include Zend_mail  and Zend_Mail_Transport_Smtp file in the file/function
   3. Set/Get the config variables
      Use the following code.
        require_once 'Zend/Mail.php';
     require_once 'Zend/Mail/Transport/Smtp.php';
    
     $config = array('auth' => 'login',
                    'username' => 'info@domainname',
                    'password' => 'password');
               
        $transport = new Zend_Mail_Transport_Smtp('smtpServer', $config);
       
    $mail = new Zend_Mail();
   
    $mail->setFrom('info@domainname', 'DO NOT REPLY');
    $mail->addTo($toEmail, 'Recipient');
    $mail->setSubject('Set Subject');
    $mail->setBodyText('Add Message');
   
    $mail->send($transport);