No adapter found for Application_Model_Table_TableName

It can occur if your Database configuration in configs/application.ini is wrong the file doesn't exist in the path

How to get checkbox 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_users')->getMultiOptions();
In the 'all_users' is the form elememnt name in the Form

How to fix the url routing when using SEO url

While we use seo url like http://domain/destination/destination-name.phtml all the url is reset to destination controller if you have not used the default attribute. To fix that you need to use the 'default' attribute with the url parameters
Ex:
$this->url(array('controller'=>'events','action'=>'new-year.html'),'default',true);

Disable select option in Zend Form

We can do that using the setAttribs property in the Zend Form Element

Ex:
$roles = new Zend_Form_Element_Select("roles");
$roles->setLabel("Roles");
$roles->addMultiOptions(array('1' => 'Admin', '2'=>'Group Admin','3'=>'User'));
suppose if we want to set it disable if the user is 'User'.
if($roleValue > 2)
$roles->setAttribs(array('disabled'=>'disabled'));

How to include view(.phtml) file in another view file

In the view file,
echo $this->partial('index/partial.phtml', 'module')

You have to create the partial.phtml in views/helpers/index folder, where index is the controller name. You can specify the module as the second parameter.

Create Form for Modules

While creating forms for the modules, we can do it by creating a folder with Module name in the /forms folder. While you name the class you have to use Form_Module_FileName and you have to same in the controller

Ex:
In /application/forms/Admin

class Form_Admin_Register extends Zend_Form{
}

In the controller you have to initiate form by using

$form = new Form_Admin_Register();

How to create custorm profile url using Zend Framework

In the boortrap file create and init function

public function _initRoute()

{
$frontController = Zend_Controller_Front::getInstance();
$route = new Zend_Controller_Router_Route(

'profile/*',array(

'controller' => 'profile',

'module' => 'default',

'action' => 'index',

'name' => ”));
$frontController->getRouter()->addRoute('profile',$route);
}
Ex: http://cochinhub.com/profile/john.steve

How to use Zend Framework Database functions for other application

- Include Zend library using set_include_path or .htaccess
- include 'Zend/Db/Table.php';
- $db = Zend_Db::factory('Pdo_Mysql', array(
'host' => 'localhost',
'username' => 'userName',
'password' => 'password',
'dbname' => 'dbName',
));

How to redirect with parameters in Zend Framework

$this->_helper->_redirector('action','controller','module',array('param1'=>'value1'));

How to get the table column names using Database functions

$result = $this->db->query($sql_query);
$result->setFetchMode(Zend_Db::FETCH_NUM);
$metaData = $this->db->describeTable('tableName');
$columnNames = array_keys($metaData);

Zend Framework : Difference ways to redirect from controller

Zend Framework 1.8 Web Application Development

1. $this->_helper->redirector('index','profile');
2. $url = $this->_helper->url('index','profile','',array('smsg'=>'moved'));
$this->_helper->redirector->goToUrl($url);
3. $this->_forward('index','profile');
PHP Zend Studio 5 - Instructor-based Video Training

Perform action with out view page in Zend Framework

$this->_helper->viewRenderer->setNoRender()

OR

$this->getHelper('viewRenderer')->setNoRender()

How to add OR condition in select query

$selectQry = $this->db->select()->where('fieldname = ?','value')
->orWhere('fieldname = ?','value);

Zend Framework select query with limit and order clause

$selectQry = $this->db->select()->from(array('MedA'=>TBL_NAME),array('answer_id','didTake','dateRecorded'))
->join(array('Med'=>TBL_NAME),
'Med.medication_id = MedA.medication_id',
array('nick_name'))
->where('MedA.is_deleted = ?',0)
->where('MedA.medication_id = ?',$medId)
->where('MedA.time_slot_id = ?',$timeSlotId)
->where('MedA.user_id = ?',$idValue)
->order('MedA.dateRecorded DESC');

if(!empty($limit))
$selectQry->limit($offset,$limit)

Create Select query with join using Zend Framework

$this->db->select()->from(array('T1'=>'TBL_1'),array('table1_id'))
->join(array('T2'=>'TBL_2'),
'T1.site_id = T2.site_id',
array('GROUP_CONCAT( T2.name) as site_name'))
->where('T1.table1_id = ?',mysql_escape_string($tableId))

Set common view file in controller for using in different actions

We can use the same view file for different actions by using the view render helper.
If we want to use the same view file for Add and Edit pages, Create a view file for Add and use the below code in the Edit action function
$this->_helper->viewRenderer->setRender('add');

How to change the default Index controller in Zend Framework

Add the following code in the bootstrap init function
$frontController = $this->getResource('FrontController');
$frontController->setDefaultControllerName('controllerName');

How to get last Insert Id in Zend Framework

If we want to get the last insert id in the Model we can use the command like this
$this->getAdapter()->lastInsertId();
Or we if we have the object of the db adapater, we can use the below code.
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$db->lastInsertId()

How to get the config variables from application.ini in Controller

You can use the below code in the controller and it will return an array of config variables.
$config = $this->getInvokeArg(‘bootstrap’)->getOptions();

Zend Form button with onclick attribute

$form = new Zend_Form();
$form->addElement('button', 'add', array(
'Label' => 'Add Person',
'order' => '2',
'attribs' => array('onclick'=>'addMemberToSharedCalendar(this)')
));