想讓url中controller、action部分兼容兼容中劃線,中劃線更加符合SEO標(biāo)準(zhǔn)也更美觀
例如 /security/update-password 將訪問(wèn) securityController 控制器的 updatePassword 方法
每條都注冊(cè)路由麻煩
閱讀了一下代碼,在
框架核心App.php 類 getControllerAction方法添加如下代碼
$controller_class = str_replace(' ', '', ucwords(str_replace('-', ' ', $controller_class)));
$action = str_replace(' ', '', ucwords(str_replace('-', ' ', $action)));
實(shí)測(cè)可行 也不會(huì)對(duì)框架現(xiàn)有用戶產(chǎn)生影響,github發(fā)了PR,但是是第一次發(fā) 不知道是不是操作有問(wèn)題群主看不到,望群主能通過(guò)下這段改動(dòng)
中劃線更加符合SEO標(biāo)準(zhǔn)也更美觀
重新發(fā)pr吧,你的pr里帶了其它文件代碼,src/Auth/AuthManger.php 什么的不要提交。
$controller_class = str_replace(' ', '', ucwords(str_replace('-', ' ', $controller_class)));
$action = str_replace(' ', '', ucwords(str_replace('-', ' ', $action)));
這個(gè)寫得太繁瑣了,改成
$controller_class = str_replace('-', ' ', $controller_class);
$action = str_replace('-', ' ', $action);
看下是否ok
我從Yii2抄過(guò)來(lái)的代碼 好像是最簡(jiǎn)單的實(shí)現(xiàn)了 你寫的這段會(huì)報(bào)錯(cuò) method名有空格
發(fā)錯(cuò)了,替換成
$controller_class = str_replace('-', '', $controller_class);
$action = str_replace('-', '', $action);
....區(qū)別很大啊 不管你訪問(wèn) index/i-index、index/in-dex、index/ind-ex都會(huì)跑到index控制器的index方法去
你pr也是一樣的效果,index/i-index、index/in-dex、index/ind-ex都會(huì)跑到index控制器的index方法去。
這樣好像確實(shí)不好
php方法命名不能重復(fù)也不區(qū)分大小寫,所以walkor那個(gè)跟你的是一樣的效果
所以不管你是function Log/LOg/LOG/lOg/loG ... 最后->log都能調(diào)用
打個(gè)比方,你要Request-For-Something, 你要精確匹配,那么方法名只能是request_for_something, - 轉(zhuǎn) _