I create a action helper file path is
C:\xampp\htdocs\ecom\application\controllers\helpers
file name :Inputdata.php
class Zend_Controller_Action_Helper_Inputdata extends Zend_Controller_Action_Helper_Abstract
{
function Inputdata()
{
return $this;
}
function fetch_db_value($var)
{
if(get_magic_quotes_gpc()==0) {
return is_array($var) ? array_map(array($this,'fetch_db_value'), $var) : nl2br(stripslashes(trim($var)));
}else {
return is_array($var) ? array_map(array($this,'fetch_db_value'), $var) : nl2br(trim($var));
}
}
}
I am calling this function on controller giving output proper like :
$dbData=$this->_helper->Inputdata->fetch_db_value($dbData);
I have also a view helper, path is
C:\xampp\htdocs\ecom\application\views\helpers
file name : Comman.php
class Zend_View_Helper_Comman
{
public function displayProducts($res){
# Res is a array
foreach($res as $val){
# $val also is sub array of array $res
$val=$this->_helper->Inputdata->fetch_db_value($val);
print_r($val)
}
}
}
this function
$this->_helper->Inputdata->fetch_db_value
is giving error
Re: the action helper:
The namespace prefix on your action helper is Zend_
. The autoloader will look for it in the location in which the Zend Framework library resides. In order for the autoloader - the resource loader, in this case - to look for the action helper in application/controllers/helpers
, the namespace prefix has to be the appnamespace
, typically Application_
. So renaming the class to Application_Controller_Helper_Inputdata
should do the trick.
Re: the view helper:
A similar thing applies. Typically, you would use the appnamespace prefix Application_
. So renaming the class to Application_View_Helper_Comman
should make the displayProducts()
method accessible in a view-script as:
$this->comman()->displayProducts($res)
You mention referencing the view-helper method in a controller. This is typically not done; view-helpers are usually referenced only in view-scripts. However, if you really want to do it, you can access it via the View object. In a controller:
$this->_view->comman()->displayProducts($res)
If that view-helper is only going to contain that single displayProducts()
method, then you can rename that class to be Application_View_Helper_DisplayProducts
and reference the method in a view-script using:
$this->displayProducts($res)