{"action":"created","issue":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/1698","labels_url":"https://api.github.com/repos/phalcon/cphalcon/issues/1698/labels{/name}","comments_url":"https://api.github.com/repos/phalcon/cphalcon/issues/1698/comments","events_url":"https://api.github.com/repos/phalcon/cphalcon/issues/1698/events","html_url":"https://github.com/phalcon/cphalcon/issues/1698","id":24309765,"number":1698,"title":"[NFR] Allow absolute paths in view","user":{"login":"Mech7","id":190633,"avatar_url":"https://avatars.githubusercontent.com/u/190633?v=3","gravatar_id":"","url":"https://api.github.com/users/Mech7","html_url":"https://github.com/Mech7","followers_url":"https://api.github.com/users/Mech7/followers","following_url":"https://api.github.com/users/Mech7/following{/other_user}","gists_url":"https://api.github.com/users/Mech7/gists{/gist_id}","starred_url":"https://api.github.com/users/Mech7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mech7/subscriptions","organizations_url":"https://api.github.com/users/Mech7/orgs","repos_url":"https://api.github.com/users/Mech7/repos","events_url":"https://api.github.com/users/Mech7/events{/privacy}","received_events_url":"https://api.github.com/users/Mech7/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phalcon/cphalcon/labels/New%20Feature%20Request","name":"New Feature Request","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2013-12-15T11:44:54Z","updated_at":"2015-06-11T12:17:33Z","closed_at":null,"body":"Currently I cannot do something like this:\r\n\r\n```php\r\n$view->setLayoutsDir(getcwd().'/app/views/layout/');\r\n```\r\nAs it will be prefixed with the path from the view dir, this makes it tricky when working with multiple module's.\r\n\r\nMy idea was installing all modules with composer, as it is not much more then a namespace. And allow modules to be anywhere under \\my\\module or under \\module so I would not know the module path.\r\n\r\nPlease allow absolute paths in the layouts dir, also It would be nice if multiple view paths are supported for multi module applications. The views can have an extra module name between the view controller dir. (similiar to zf2)\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/1896326-nfr-allow-absolute-paths-in-view?utm_campaign=plugin&utm_content=tracker%2F50707&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F50707&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/comments/111112190","html_url":"https://github.com/phalcon/cphalcon/issues/1698#issuecomment-111112190","issue_url":"https://api.github.com/repos/phalcon/cphalcon/issues/1698","id":111112190,"user":{"login":"kevas","id":227353,"avatar_url":"https://avatars.githubusercontent.com/u/227353?v=3","gravatar_id":"","url":"https://api.github.com/users/kevas","html_url":"https://github.com/kevas","followers_url":"https://api.github.com/users/kevas/followers","following_url":"https://api.github.com/users/kevas/following{/other_user}","gists_url":"https://api.github.com/users/kevas/gists{/gist_id}","starred_url":"https://api.github.com/users/kevas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevas/subscriptions","organizations_url":"https://api.github.com/users/kevas/orgs","repos_url":"https://api.github.com/users/kevas/repos","events_url":"https://api.github.com/users/kevas/events{/privacy}","received_events_url":"https://api.github.com/users/kevas/received_events","type":"User","site_admin":false},"created_at":"2015-06-11T12:17:33Z","updated_at":"2015-06-11T12:17:33Z","body":"```\r\n$di->set('view', function() {\r\n    $view = new MyView();\r\n    return $view;\r\n});\r\n\r\nclass MyView extends \\Phalcon\\Mvc\\View {\r\n    \r\n    protected function _engineRender($engines, $viewPath, $silence, $mustClean, \\Phalcon\\Cache\\BackendInterface $cache = null) {\r\n\r\n        $path = realpath(dirname($viewPath));\r\n        if($path !== false && $path !== realpath(PUBLIC_PATH)) {\r\n            $basename = basename($viewPath);\r\n            $viewPathArr = explode('/', $viewPath);\r\n            $viewPathArrSlice = array_slice($viewPathArr, 1, -1);\r\n            $viewPath = str_repeat('../', count($viewPathArrSlice)) . implode('/', $viewPathArrSlice) . '/' . $basename;\r\n        }\r\n\r\n        parent::_engineRender($engines, $viewPath, $silence, $mustClean, $cache = null);\r\n    }\r\n}\r\n```\r\n\r\nConstant PUBLIC_PATH is a path directory where is index.php file.\r\nAnd then you can write absolute path to the method setLayoutsDir - $view->setLayoutsDir('/var/www/web/app/views/layout/');"}}