A custom function that I can use in all my controllers

I have a project and I am using ZendFramework, also I am new to this Framework.

So my problem is:

I want to create a user-defined function that I can use in all controllers. Example. I want to create a function that will check an input field in which I will use trim, htmlspecialchars and mysql_real_escape_string. I want to access this feature in all controllers.

I have a solution for this, that I will create this function in every controller that I have, which I consider to be not the best solution.

thank

+5
source share
3 answers

- , . , .

/ Action Controllers, Zend_Controller_Action. , Action Controller.

, .

, , application.ini:

resources.frontController.actionHelperPaths.My_Controller_Action_Helper = "My/Controller/Action/Helper/"

My - .

My/Controller/Action/Helper/ MyActionHelper.php :

class My_Controller_Action_Helper_MyActionHelper extends Zend_Controller_Action_Helper_Abstract
{
    public function direct($input)
    {
        $output = mysql_real_escape_string($input);
        // trim, etc.
        return $output;
    }
}

, ! , , $this->_helper->myActionHelper($input);.

, , Zend_Form Zend_Filter. Zend_Filter StripTags TrimString, .

+8

Util.php , , index.php( )

require_once 'Util.php';

require_once 'Zend/Application.php';

, , Util.php

    function mysql_real_escape_string($value)
    {
    return $value 
    }

    function logger($value)
    {
      Zend_Regsitry::get('logger')->log($value);
    }

  function _T($translate)
{
return Zend_Registry::get('translator')->translate($translate);
}

, zf. ZF. .

+1

The Zend Framework has Zend_Controller_Action_Helper .

0
source

All Articles