Nette nevie najst sluzbu, ale v Tracy vidim, ze je nacitana
- steelbull
- Člen | 241
Dostavam nasledujucu hlasku:
Service of type App\Components\MyGrid used in @var annotation at App\Presenters\MyPresenter::$MyGrid not found. Did you register it in configuration file?
config.neon
- implement: App\Components\IMyGrid
interface komponenty vyzera takto:
/**
* Interface IMyGrid
* @package App\Components
*/
interface IMyGrid
{
/**
* Method create
* @return \App\Components\MyGrid
*/
public function create();
}
V presenteri injectujem nasledovne:
/** @var \App\Components\MyGrid @inject */
public $myGrid;
A v Tracy vidim, ze sluzba existuje.
- steelbull
- Člen | 241
jj, to som urobil, vid poslednu cast mojej otazky. A ked ju v presenteri injectujem, sprava sa to, ako keby som injektoval nieco, co nemam definovanie v neone, ale mam. Inicializujem ju dobre v neone?
Edit:
ked injectujem IMyGrid, tak injectne, ale potom v presenteri
v createComponentMyGrid dojde k chybe, ze vystup nie je potomkom
UI\Control;
protected function createComponentMyGrid()
{
return $this->MyGrid;
}
Editoval steelbull (10. 1. 2017 11:45)
- steelbull
- Člen | 241
Cely komponent…
<?php
namespace App\Components;
use Nette\Application\UI\Control,
Nette\Database\Context,
Nette\Security\User,
Nette\Http\Request,
Kendo;
/**
* Class MyGrid
* @package App\Components
*/
class MyGrid extends Control
{
private $context;
private $user;
private $request;
/**
* MyGridControl constructor.
* @param Context $context
* @param User $user
* @param Request $request
*/
public function __construct(Context $context, User $user, Request $request)
{
$this->context = $context;
$this->user = $user;
$this->request = $request;
}
/**
* Method render
*/
public function render()
{
// Tu renderujem datagrid
// a potom zobrazim
echo $grid->render();
}
public function handleLoaddata()
{
// Loaduje data cez json...
}
}
}
/**
* Interface IMyGrid
* @package App\Components
*/
interface IMyGrid
{
/**
* Method create
* @return \App\Components\MyGrid
*/
public function create();
}
- steelbull
- Člen | 241
a ked dumpnem $this->MyGrid v presenteru, tak to vypise class@anonymous:
class@anonymous #5c67
container private => Container_bb8e3d005d #6e7b
meta protected => array (4)
types => array (155) [ ... ]
services => array (123) [ ... ]
tags => array (5) [ ... ]
aliases => array (18) [ ... ]
parameters => array (7)
registry private => array (37)
creating private => array ()
- David Matějka
- Moderator | 6445
musis volat $this->myGrid->create()
, jelikoz tam mas
injectnutou tovarnu a ne samotnout komponentu.
a doporucuji trochu upravit nazvy, IMyGrid ⇒ IMyGridFactory (pripadne jen MyGridFactory), nejde totiz o interface te komponenty, ale tovarny na komponentu. a v presenteru, jak si injectujes myGrid, tak prejmenuj na myGridFactory