{"action":"created","issue":{"url":"https://api.github.com/repos/mixstart/mixphp/issues/15","repository_url":"https://api.github.com/repos/mixstart/mixphp","labels_url":"https://api.github.com/repos/mixstart/mixphp/issues/15/labels{/name}","comments_url":"https://api.github.com/repos/mixstart/mixphp/issues/15/comments","events_url":"https://api.github.com/repos/mixstart/mixphp/issues/15/events","html_url":"https://github.com/mixstart/mixphp/issues/15","id":313242507,"number":15,"title":"视图渲染问题","user":{"login":"dhdbuwl","id":5136528,"avatar_url":"https://avatars0.githubusercontent.com/u/5136528?v=4","gravatar_id":"","url":"https://api.github.com/users/dhdbuwl","html_url":"https://github.com/dhdbuwl","followers_url":"https://api.github.com/users/dhdbuwl/followers","following_url":"https://api.github.com/users/dhdbuwl/following{/other_user}","gists_url":"https://api.github.com/users/dhdbuwl/gists{/gist_id}","starred_url":"https://api.github.com/users/dhdbuwl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhdbuwl/subscriptions","organizations_url":"https://api.github.com/users/dhdbuwl/orgs","repos_url":"https://api.github.com/users/dhdbuwl/repos","events_url":"https://api.github.com/users/dhdbuwl/events{/privacy}","received_events_url":"https://api.github.com/users/dhdbuwl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-11T09:26:57Z","updated_at":"2018-04-11T11:55:10Z","closed_at":null,"author_association":"NONE","body":"当在controllers目录下建立了子目录时，视图文件按规则建立，渲染会出问题。\r\n例如：apps\\index\\controllers下新建目录admin，admin目录下新建控制器LoginController.php，控制器只有actionIndex方法\r\napps\\index\\views下新建目录admin\\login，login目录下新建视图文件index.php\r\n这种情况下无法找到视图文件，视图文件路径为 admin/_login/index.php，查看源码后发现是Mix\\Base\\Route中的camelToSnake()方法不够严谨导致的，原代码如下\r\n```\r\n// 驼峰命名转换为蛇形命名\r\n    public static function camelToSnake($name, $separator = '_')\r\n    {\r\n        $name = preg_replace_callback('/([A-Z]{1})/', function ($matches) use ($separator) {\r\n            return $separator . strtolower($matches[0]);\r\n        }, $name);\r\n        if (substr($name, 0, 1) == $separator) {\r\n            return substr($name, 1);\r\n        }\r\n        return $name;\r\n    }\r\n```\r\n该代码只去除了头部的分隔符。有子目录的情况下，_admin._login的后一个_也是应该要去除的，我试着修改了下代码，如下\r\n```\r\n// 驼峰命名转换为蛇形命名\r\n    public static function camelToSnake($name, $separator = '_')\r\n    {\r\n        $name = preg_replace_callback('/([A-Z]{1})/', function ($matches) use ($separator) {\r\n            return $separator . strtolower($matches[0]);\r\n        }, $name);\r\n        //add by Loay. Fix view render issue.\r\n        $name = str_replace('.'.$separator, '.', $name);\r\n        if (substr($name, 0, 1) == $separator) {\r\n            return substr($name, 1);\r\n        }\r\n        return $name;\r\n    }\r\n```"},"comment":{"url":"https://api.github.com/repos/mixstart/mixphp/issues/comments/380425611","html_url":"https://github.com/mixstart/mixphp/issues/15#issuecomment-380425611","issue_url":"https://api.github.com/repos/mixstart/mixphp/issues/15","id":380425611,"user":{"login":"onanying","id":16074765,"avatar_url":"https://avatars0.githubusercontent.com/u/16074765?v=4","gravatar_id":"","url":"https://api.github.com/users/onanying","html_url":"https://github.com/onanying","followers_url":"https://api.github.com/users/onanying/followers","following_url":"https://api.github.com/users/onanying/following{/other_user}","gists_url":"https://api.github.com/users/onanying/gists{/gist_id}","starred_url":"https://api.github.com/users/onanying/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onanying/subscriptions","organizations_url":"https://api.github.com/users/onanying/orgs","repos_url":"https://api.github.com/users/onanying/repos","events_url":"https://api.github.com/users/onanying/events{/privacy}","received_events_url":"https://api.github.com/users/onanying/received_events","type":"User","site_admin":false},"created_at":"2018-04-11T11:55:10Z","updated_at":"2018-04-11T11:55:10Z","author_association":"OWNER","body":"视图文件路径 `admin/_login/index.php` 中间为什么要加一个 `_` ?"}}
{"actor":{"display_login":"onanying"}}