Dependency injection - landrisek/impala GitHub Wiki

Injection

First inject IBuilder and IRowBuilder. /** @var \Impala\IBuilder * /     public $grid; /** @var \Impala\IRowBuilder * /     public $row; There are kinds of value objects holding your SQL or noSQL queries before fetching. Injection of grid and edit row components is following: /** @var \Impala\IImpalaFactory @inject * /     public $impalaFactory; /** @var \Impala\IImpalaFormFactory @inject * /     public $impalaFormFactory;

Presenter action method

Define your builder (value objects) source tables, selection of columns and where clauses in presenter action method by similar way as in Nette Database: public actionDefault($value) {     $this->grid->table('table')         ->where('column', $value); } As third parameter you can include callback which if return false, then given where clause will be omited.     ->where('column', $value, function($value) { return !empty($value); }) Native queries are supported by method leftJoin / innerJoin / join which when used, it is obvious NetteDatabase with foreign key cannot be used:     ->leftJoin('table ON table.column = table2.column2')

Create components

protected function createComponentImpala() {     return $this->ImpalaFactory->create()       ->setGrid($this->grid); } protected function createComponentImpalaForm() {     return $this->ImpalaFormFactory->create()         ->setRow($this->row); }

IBuilder in repository class

You can add grid dependency in model and define all necessary sources and clauses directly in your repository public function __construct(\Impala\IBuilder $grid) {     $this->grid = $grid } /** @return \Impala\IBuilder */ public function getGrid($value) {     return $this->grid->table($this->getSource())             ->where('column', $value); } In this way you can have queries outside of presenters and keep your code clean.

Template

Native template system for Impala is latte {control impala} {control impalaForm}

Using more grids on same page

Action method in presenter: public actionDefault() {     $this->grid->table($table)     $this->anotherGrid->cloned()->table($table) } Create component method: protected function createComponentAnotherImpala() {     return $this->ImpalaFactory->cloned()->create()                 ->setGrid($this->anotherGrid); }