{"action":"created","issue":{"url":"https://api.github.com/repos/slimphp/Twig-View/issues/30","labels_url":"https://api.github.com/repos/slimphp/Twig-View/issues/30/labels{/name}","comments_url":"https://api.github.com/repos/slimphp/Twig-View/issues/30/comments","events_url":"https://api.github.com/repos/slimphp/Twig-View/issues/30/events","html_url":"https://github.com/slimphp/Twig-View/pull/30","id":99228011,"number":30,"title":"Implemented correct DI for baseUrl","user":{"login":"yurevichcv","id":67401,"avatar_url":"https://avatars.githubusercontent.com/u/67401?v=3","gravatar_id":"","url":"https://api.github.com/users/yurevichcv","html_url":"https://github.com/yurevichcv","followers_url":"https://api.github.com/users/yurevichcv/followers","following_url":"https://api.github.com/users/yurevichcv/following{/other_user}","gists_url":"https://api.github.com/users/yurevichcv/gists{/gist_id}","starred_url":"https://api.github.com/users/yurevichcv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yurevichcv/subscriptions","organizations_url":"https://api.github.com/users/yurevichcv/orgs","repos_url":"https://api.github.com/users/yurevichcv/repos","events_url":"https://api.github.com/users/yurevichcv/events{/privacy}","received_events_url":"https://api.github.com/users/yurevichcv/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-05T15:12:21Z","updated_at":"2015-08-06T09:26:57Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/slimphp/Twig-View/pulls/30","html_url":"https://github.com/slimphp/Twig-View/pull/30","diff_url":"https://github.com/slimphp/Twig-View/pull/30.diff","patch_url":"https://github.com/slimphp/Twig-View/pull/30.patch"},"body":"There is no need to path full `\\Slim\\Http\\Uri` object inside extension, as far as you need only `baseUrl`. So, instead you should inject **ONLY** what you need. But, for backward compatibility I saved possibility to pass whole `\\Slim\\Http\\Uri`object.\r\n\r\nSo, correct way to create Twig extension now will look like this:\r\n\r\n```\r\n$view->addExtension(new Slim\\Views\\TwigExtension(\r\n    $container->get('router'),\r\n    $container->get('request')->getUri()->getBaseUrl()\r\n));\r\n```\r\n\r\nOR:\r\n\r\n```\r\n$view->addExtension(new Slim\\Views\\TwigExtension(\r\n    $container->get('router'),\r\n    $container->get('settings')['baseUrl']\r\n));\r\n```\r\n\r\nOR\r\n\r\n```\r\n$view->addExtension(new Slim\\Views\\TwigExtension(\r\n    $container->get('router'),\r\n    'http://mywebsite.com'\r\n));\r\n```"},"comment":{"url":"https://api.github.com/repos/slimphp/Twig-View/issues/comments/128305114","html_url":"https://github.com/slimphp/Twig-View/pull/30#issuecomment-128305114","issue_url":"https://api.github.com/repos/slimphp/Twig-View/issues/30","id":128305114,"user":{"login":"yurevichcv","id":67401,"avatar_url":"https://avatars.githubusercontent.com/u/67401?v=3","gravatar_id":"","url":"https://api.github.com/users/yurevichcv","html_url":"https://github.com/yurevichcv","followers_url":"https://api.github.com/users/yurevichcv/followers","following_url":"https://api.github.com/users/yurevichcv/following{/other_user}","gists_url":"https://api.github.com/users/yurevichcv/gists{/gist_id}","starred_url":"https://api.github.com/users/yurevichcv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yurevichcv/subscriptions","organizations_url":"https://api.github.com/users/yurevichcv/orgs","repos_url":"https://api.github.com/users/yurevichcv/repos","events_url":"https://api.github.com/users/yurevichcv/events{/privacy}","received_events_url":"https://api.github.com/users/yurevichcv/received_events","type":"User","site_admin":false},"created_at":"2015-08-06T09:26:57Z","updated_at":"2015-08-06T09:26:57Z","body":"Fundamental mistake here is using the following:\r\n\r\n```\r\n$view->addExtension(new Slim\\Views\\TwigExtension(\r\n    $container->get('router'),\r\n    $container->get('request')->getUri()\r\n));\r\n```\r\n\r\n1. Request object is immutable. This way if you make changes to $request object inside Middleware you initial extension setup will be not valid anymore.\r\n\r\n2. Also, sometimes you may need to use Slim's sub-requests. They will have absolutely different `$request` objects. But you extension will still use the very first `$uri` you've got from container initially. This will lead to unpredictable behaviour.\r\n\r\n3. If I'm building API - I may use templates only in rare situations when I need to render some email templates or generate links to some UI-enpoints. In most cases all URL links will have **absolutely different** base URL, not connected with current request and current API url.\r\n\r\n4. And finally, it also breaks Unit Tests concept. In my Unit tests I create `App` object once. And then \"feed\" it with different `$request` objects. With current solution template engine will be initialised with the very first `$request` object, and all others will be ignored.\r\n\r\nThat's why to make predictable way of view initialisation - base url, base path, or whatever else should be provided explicitly.\r\n\r\nOn my opinion base_url helper should be removed from Slim Twig Extensions at all, as it has nothing to do with the Slim Framework. As well as your PR. If you need base_path functionality - you can create separate extension.\r\n\r\nOnly 'path_for' functionality is deeply connected with Slim Routing system and needs to be saved.\r\n"}}