You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

49 lines
1.6 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2017/10/26
  6. * Time: 16:50
  7. */
  8. namespace common\components;
  9. use \yii\base\Controller;
  10. use yii\base\InlineAction;
  11. class zController extends Controller //这里需要继承自\yii\base\Controller
  12. {
  13. /**
  14. * Author:Steven
  15. * Desc:重写路由,处理访问控制器支持驼峰命名法
  16. * @param string $id
  17. * @return null|object|InlineAction
  18. */
  19. public function createAction($id)
  20. {
  21. if ($id === '') {
  22. $id = $this->defaultAction;
  23. }
  24. $actionMap = $this->actions();
  25. if (isset($actionMap[$id])) {
  26. return \Yii::createObject($actionMap[$id], [$id, $this]);
  27. } elseif (preg_match('/^[a-z0-9\\-_]+$/', $id) && strpos($id, '--') === false && trim($id, '-') === $id) {
  28. $methodName = 'action' . str_replace(' ', '', ucwords(implode(' ', explode('-', $id))));
  29. if (method_exists($this, $methodName)) {
  30. $method = new \ReflectionMethod($this, $methodName);
  31. if ($method->isPublic() && $method->getName() === $methodName) {
  32. return new InlineAction($id, $this, $methodName);
  33. }
  34. }
  35. } else {
  36. $methodName = 'action' . $id;
  37. if (method_exists($this, $methodName)) {
  38. $method = new \ReflectionMethod($this, $methodName);
  39. if ($method->isPublic() && $method->getName() === $methodName) {
  40. return new InlineAction($id, $this, $methodName);
  41. }
  42. }
  43. }
  44. return null;
  45. }
  46. }