{"action":"created","issue":{"url":"https://api.github.com/repos/auraphp/Aura.Router/issues/114","repository_url":"https://api.github.com/repos/auraphp/Aura.Router","labels_url":"https://api.github.com/repos/auraphp/Aura.Router/issues/114/labels{/name}","comments_url":"https://api.github.com/repos/auraphp/Aura.Router/issues/114/comments","events_url":"https://api.github.com/repos/auraphp/Aura.Router/issues/114/events","html_url":"https://github.com/auraphp/Aura.Router/issues/114","id":141724410,"number":114,"title":"Using the Generator as a View Helper","user":{"login":"jakejohns","id":174708,"avatar_url":"https://avatars.githubusercontent.com/u/174708?v=3","gravatar_id":"","url":"https://api.github.com/users/jakejohns","html_url":"https://github.com/jakejohns","followers_url":"https://api.github.com/users/jakejohns/followers","following_url":"https://api.github.com/users/jakejohns/following{/other_user}","gists_url":"https://api.github.com/users/jakejohns/gists{/gist_id}","starred_url":"https://api.github.com/users/jakejohns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakejohns/subscriptions","organizations_url":"https://api.github.com/users/jakejohns/orgs","repos_url":"https://api.github.com/users/jakejohns/repos","events_url":"https://api.github.com/users/jakejohns/events{/privacy}","received_events_url":"https://api.github.com/users/jakejohns/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-17T22:38:44Z","updated_at":"2016-03-23T19:27:24Z","closed_at":null,"body":"I want to use the `Generator` in a view script.\r\nIt seems like I want to be able to do it like this, I guess?\r\n```php\r\n// view.php\r\necho $this->a(\r\n    $this->url()->generate('route', $params),\r\n    'click here'\r\n);\r\n// or possibly even:\r\necho $this->a(\r\n    $this->url('route', $params),\r\n    'click here'\r\n);\r\n```\r\n\r\nI did it like this the other day, and it seemed a little awkward.\r\nI set up my DI to grab the Aura\\Html helper locator, and set the `url` key to a\r\n`lazyGetCall` on the router, and then wrapped that in a function...\r\n\r\n```php\r\n<?php\r\nclass Config extends ContainerConfig\r\n{\r\n    public function modify(Container $di)\r\n    {\r\n        $helpers = $di->get('aura/html:helpers');\r\n        $url = $di->lazyGetCall('radar/adr:router', 'getGenerator');\r\n        $helpers->set(\r\n            'url',\r\n            function () use ($url) {\r\n                return $url;\r\n            }\r\n        );\r\n    }\r\n}\r\n```\r\n\r\n...That seems pretty weird though.\r\n\r\nIf `Generator` had this:\r\n```php\r\n//...\r\npublic function __invoke($name = null, $data = [])\r\n{\r\n    if (null == $name) {\r\n        return $this;\r\n    }\r\n\r\n    return $this->generate($name, $data);\r\n}\r\n```\r\n\r\nI wouldn't need to wrap it in a function to use with the helpers, and I could\r\njust call `$this->url(...)`, instead of\r\n`$this->url()->generate(...)`, but if needed, could also\r\n`$this->url()->generateRaw(...)`\r\n\r\n\r\nHowever, again... it doesnt seem quite right to me to add the `__invoke` method\r\nlike that in the `Generator`.\r\n\r\nMaybe I should just be adding it into the view and not mess with the helpers?\r\neg:\r\n\r\n```php\r\n<?php\r\nclass Config extends ContainerConfig\r\n{\r\n    public function modify(Container $di)\r\n    {\r\n        $view = $di->get('aura/view:view');\r\n        $generator = $di->get('radar/adr:router')->getGenerator();\r\n        $view->addData(['urlHelper' => $generator]);\r\n    }\r\n}\r\n\r\n// in view:\r\necho $this->a(\r\n    $this->urlHelper->generate('route', $params),\r\n    'click here'\r\n);\r\n```\r\n\r\nAre other people doing this?\r\nThoughts? Recommendations? Best Practices?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/auraphp/Aura.Router/issues/comments/200506737","html_url":"https://github.com/auraphp/Aura.Router/issues/114#issuecomment-200506737","issue_url":"https://api.github.com/repos/auraphp/Aura.Router/issues/114","id":200506737,"user":{"login":"jakejohns","id":174708,"avatar_url":"https://avatars.githubusercontent.com/u/174708?v=3","gravatar_id":"","url":"https://api.github.com/users/jakejohns","html_url":"https://github.com/jakejohns","followers_url":"https://api.github.com/users/jakejohns/followers","following_url":"https://api.github.com/users/jakejohns/following{/other_user}","gists_url":"https://api.github.com/users/jakejohns/gists{/gist_id}","starred_url":"https://api.github.com/users/jakejohns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakejohns/subscriptions","organizations_url":"https://api.github.com/users/jakejohns/orgs","repos_url":"https://api.github.com/users/jakejohns/repos","events_url":"https://api.github.com/users/jakejohns/events{/privacy}","received_events_url":"https://api.github.com/users/jakejohns/received_events","type":"User","site_admin":false},"created_at":"2016-03-23T19:27:24Z","updated_at":"2016-03-23T19:27:24Z","body":"I had been working on decorating the generator, and thought it a bit gratuitous, but perhaps my initial impulse was correct. @dlundgren, got a package, or any public code? I'd be curious to see your solution concretely.  I'm also curious if the \"etc\" in your list of URL functionality includes something like a mechanism for determining active state of a link. Right now, my responders are setting the PSR7 Request object to the view and I'm doing things like this for navigation:\r\n```php\r\nforeach ($items as $name => $route) {\r\n    $url = $this->urlHelper->generate($route);\r\n    $attr = $this->request->getUri()->getPath() == $url ? ['class' => 'active'] : [];\r\n    $menu->rawItem($this->anchor($url, $name), $attr);\r\n}\r\n```"}}