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

editable cell for doctrine orm #42

Open semihs opened 9 years ago

semihs commented 9 years ago

i received fatal error when i use editable row with doctrine orm

error;

Fatal error: Cannot use object of type Application\Entity\Accounts as array in /var/www/dev.kultureltv.com/vendor/dudapiotr/zftable/src/ZfTable/Decorator/Row/VarAttr.php on line 43

my zftable model;

namespace Application\DataTable; use ZfTable\AbstractTable; class Accounts extends AbstractTable { protected $config = array( 'showPagination' => true, 'showQuickSearch' => false, 'showItemPerPage' => true, 'showColumnFilters' => true, 'rowAction' => '/ajax/account/update', );

protected $headers = array(
    'id' => array('title' => 'Id', 'width' => '50'),
    'fullName' => array('tableAlias' => 'q', 'title' => 'İsim', 'filters' => 'text', 'editable' => true),
    'username' => array('tableAlias' => 'q', 'title' => 'Giriş', 'filters' => 'text', 'editable' => true),
    'email' => array('tableAlias' => 'q', 'title' => 'E-posta', 'filters' => 'text'),
    'status' => array(
        'tableAlias' => 'q',
        'title' => 'Durum',
        'filters' => array(
            null => 'Tümü',
            'ACTIVE' => 'Aktif',
            'PASSIVE' => 'Pasif'
        ),
        'editable' => true),
    'dateOfCreation' => array('tableAlias' => 'q', 'title' => 'Kayıt Tarihi', 'filters' => 'text'),
    'edit' => array('title' => 'Güncelle'),
);

public function init()
{
    $this->getHeader('fullName')->getCell()->addDecorator('editable');
    $this->getRow()->addDecorator('varattr', array('name' => 'data-row' , 'value' => '%s' , 'vars' => array('id')));

    $this->getHeader('dateOfCreation')->getCell()->addDecorator('callable', array(
        'callable' => function ($context, $record) {
            return $record->getDateOfCreation()->format('d/m/Y H:i:s');
        }
    ));
}

protected function initFilters($query)
{
    if ($value = $this->getParamAdapter()->getValueOfFilter('fullName')) {
        $query->where("q.fullName like '%" . $value . "%' ");
    }
    if ($value = $this->getParamAdapter()->getValueOfFilter('username')) {
        $query->where("q.username like '%" . $value . "%' ");
    }
    if ($value = $this->getParamAdapter()->getValueOfFilter('email')) {
        $query->where("q.email like '%" . $value . "%' ");
    }
    if ($value = $this->getParamAdapter()->getValueOfFilter('status')) {
        $query->where("q.status like '%" . $value . "%' ");
    }
}

}

aNorthernSoul commented 9 years ago

My Temporary solution required an edit in /vendor/dudapiotr/zftable/src/ZfTable/Decorator/Row/VarAttr.php

     /**
     * 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;
    }
semihs commented 9 years ago

yes i have solved temporary.

https://github.com/noc-med/ZfTable/commit/bc2f830fbece04d983f8ccbddfb6db789b772ba6

vraskin commented 7 years ago

Did you just change it directly in the VarAttr class? Or did you extend the class, and changed it in your version?

aNorthernSoul commented 7 years ago

I changed it directly in the class in the source files as I was hoping it was just temporary and that a long term fix would be committed to the repo. I am still waiting on that though unfortunately.