dudapiotr / ZfTable

*Not supported*ZfTable 3.1. Awesome ZF2 table / grid (and much much more) generator with huge possibilities of decorating and conditioning. Integrated with DataTables, Doctrine 2, Bootstrap 2.0 and 3.0.
http://dudapiotrek.laohost.net/
MIT License
75 stars 59 forks source link

Template Decorator trying to access Doctrine entity as an array #54

Open ixigen opened 9 years ago

ixigen commented 9 years ago

Fatal error: Cannot use object of type Application\Entity\User as array in /www/vendor/dudapiotr/zftable/src/ZfTable/Decorator/Cell/Template.php on line 58

There two options that I can think of: 1) Array Hydration for Doctrine entities 2) modify the code to access the Doctrine entities as entities not as arrays

Temporary solution:

/**
 * Rendering decorator
 *
 * @param string $context
 * @return string
 */
public function render($context)
{
    $values = array();

    foreach ($this->vars as $var) {
        $actualRow = $this->getCell()->getActualRow();

        // if it's not an array try to use a getter method
        if (is_array($actualRow)){
            $values[] = $actualRow[$var];
        } else {
            $getter = 'get'.ucfirst($var);
            $values[] = $actualRow->$getter();
        }
    }

    $value = vsprintf($this->template, $values);

    if ($this->place == self::RESET_CONTEXT) {
        return $value;
    } else {
        return ($this->place == self::PRE_CONTEXT) ? $value . $context :  $context . $value;
    }
}
aNorthernSoul commented 9 years ago

Similar issue in ZfTable\Decorator\Row\VarAttr throwing Cannot use object of type Entity as array in vendor/dudapiotr/zftable/src/ZfTable/Decorator/Row/VarAttr.php on line 42

My Temporary solution:

     /**
     * Rendering decorator
     *
     * @param string $context
     * @return string
     */
    public function render($context)
    {
        $values = array();
        foreach ($this->vars as $var) {
            $actualRow = $this->getRow()->getActualRow();
            if ( is_object($actualRow) ) {
                $values[] = $actualRow->$var;
            }else {
                $values[] = $actualRow[$var];
            }
        }
        $value = vsprintf($this->value, $values);
        $this->getRow()->addVarAttr($this->name, $value);
        return $context;
    }
W33k3nd commented 9 years ago

He solved this problem https://github.com/dudapiotr/ZfTable/blob/master/src/ZfTable/Decorator/Cell/Template.php#L58.

dustinlawrence commented 8 years ago

The issue still exists in ZfTable\Decorator\Row\VarAttr.php