zenify / doctrine-methods-hydrator
v5.1.1
2015-11-03 11:54 UTC
Requires
- php: >=5.6
- doctrine/orm: ~2.4
- nette/application: ~2.3
- nette/di: ~2.3
Requires (Dev)
- kdyby/doctrine: ~3.0
- latte/latte: ~2.3
- nette/bootstrap: ~2.3
- tracy/tracy: ~2.3
README
安装
$ composer require zenify/doctrine-methods-hydrator
在config.neon
中注册扩展
extensions: - Zenify\DoctrineMethodsHydrator\DI\MethodsHydratorExtension # Kdyby\Doctrine or another Doctrine to Nette implementation
此扩展的目标是增强Control
的原生tryCall
方法,以水化被调用方法的参数。如果args定义中存在实体类类型提示,则所有render*
、action*
和handle*
方法都会被水化。
使用方法
在presenter中的使用如下
class Presenter extends Nette\Application\UI\Presenter { /** * @inject * @var Zenify\DoctrineMethodsHydrator\Contract\MethodsHydratorInterface */ public $methodsHydrator; /** * @param string $method * @param array $parameters * @return bool */ protected function tryCall($method, array $parameters) { return $this->methodsHydrator->hydrate($method, $parameters, $this); } }
对于Control
,您可以使用构造函数或通过DecoratorExtension使用@inject
。
用例
在模板中
<a n:href="Product:detail, product => $product->getId()">Product detail</a>
在presenter中
class SomePresenter extends Presenter { public function actionDetail(App\Entities\Product $product) { dump($product); // "App\Entities\Product" object } }