dongming6201 2014-11-19 15:30
浏览 17

Action帮助程序如何与视图助手通信

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

  1. any idea about syntax how to user action helper custom function in view helper custom function
  2. syntax how call function displayProducts() on controller
  • 写回答

1条回答 默认 最新

  • doujingao6210 2014-11-20 11:41
    关注

    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)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集