how to use KnpDoctrineBehaviors translation trait

basically, you need to do this: for twig, for controller and for something in doctrine,
 /**
     * @param $method
     * @param $arguments
     * @return mixed
     * this function is used for php controller, when we call an getter or setter of translation class
     * for twig, if we do not define the isset function, we need to add an get before the method name.
     * and this function is only for getter or settercho
     */
    public function __call($method, $arguments)
    {
        $prefix=substr($method,0,3);
        if ($prefix != "get" && $prefix != "set"){
            $method="get".ucwords($method);
        }
        return $this->proxyCurrentLocaleTranslation($method, $arguments);
    }


    /**
     * @param $property
     * @return mixed
     * this function is used to get a property from translation class(in form or twig)
     */
    public function __get($property){
        $method="get".ucwords($property);
        return $this->proxyCurrentLocaleTranslation($method, array());
    }

    /**
     * @param $property
     * @param $value
     * @return mixed
     * this function is used to set property for translation class. (in form or twig)
     */
    public function __set($property, $value){
        $method="set".ucwords($property);
        $arguments=array($value);
        return $this->proxyCurrentLocaleTranslation($method, $arguments);
    }

评论

热门博文