> On Jun 9, 2015, at 08:44, Michael Kimsal <
mgki...@gmail.com> wrote:
>
> I'm somewhat new to aura - been using various pieces for last couple of months, and digging it (thanks!)
>
> I can't seem to find a way to use the html helpers with my view while also using my own helpers. The examples all show just passing one helper factory to the view instance. Any new helpers I try to register with 'set' don't seem to work right
>
> $h = $view->getHelpers();
> $h->set("foo", function() {
> // do something here
> });
>
> This would let me use $this->foo() in a view, but after adding the HTML helpers, none of this works anymore - I get errors like "Warning: Missing argument 1 for lib\ViewParse::lib\{closure}(), called in /var/www/vendor/aura/html/src/HelperLocator.php on line 118"
Here's the fundamental difference:
- The HelperRegistry built into the View package is simpler and expects closures or pre-built callable objects (it's only a Registry so it handles only object retrieval). It gets you off the ground fast.
- The HelperLocator of Aura.Html is somewhat more complex, and expects *factories* for the helper objects (it's a Locator so it also handles object creation). It servers better for longer-term maintenance.
That makes them very different systems. Being able to use very different helper systems in Aura.View is both a pro and a con; it's a pro because you get to use what you want, but it's a con because you have to change how you think when you move to a different system.
The solution here is to write your helpers as invokable objects, and pass a factory closure to the Aura.Html HelperLocator. For example:
```php
class FooHelper
{
public function __invoke()
{
// do something here
}
}
$h = $view->getHelpers();
$h->set('foo', function () { return new Foo; });
```
Let me know if that helps.
--
Paul M. Jones
pmjo...@gmail.com
http://paul-m-jones.com
Modernizing Legacy Applications in PHP
https://leanpub.com/mlaphp
Solving the N+1 Problem in PHP
https://leanpub.com/sn1php