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

Call initializable always by render #67

Closed W33k3nd closed 3 years ago

W33k3nd commented 9 years ago

$this->initializable() is always called, because $this->isTableInit() is always false and would never set true. $tableInit is private and no method exist to change this variable.

My problem is, i can't change cell or rows outside my class. I want set the url in my controller and can't, because header exist till first i call render(). After i call the render() again in my view, all properties are overwrite, because $this->initializable() is again called. e.g.:

//In my controller (or view)

$table = new CustomzfTable();
$table->getHeader('url')->getCell()->addDecorator('template', array('template'=>'<url href="'.$this->url()->fromRoute('user', array('id'=>'%s')).'" class="btn btn-default">User</a', 'vars' => array('id'))));

Did you mean here: AbstractTable.php

    /**
     * Init configuration like setting header, decorators, filters and others
     * (call in render method as well)
     */
    protected function initializable()
    {
        if(!$this->getParamAdapter()){
            throw new Exception\LogicException('Param Adapter is required');
        }
        if(!$this->getSource()){
            throw new Exception\LogicException('Source data is required');
        }

        $this->init = true;  //did you mean here $this->tableInit = true, $this->init doesn't exist

        if (count($this->headers)) {
            $this->setHeaders($this->headers);
        }
        $this->init();

        $this->initFilters($this->getSource()->getSource());
    }

I added a constructor, who create all $this->headers in my class. To avoid overwrite my created headerObject and check for exist header in addHeader().

Why you create the headerObject not till then you call render()?

Sorry for my bad English. :-)

dudapiotrek commented 9 years ago

You are absolutely right. I think it will be refactored in next version ...