AdminMenuAR.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * summary: 管理员菜单
  4. * author: justin
  5. * date: 2014.03.04
  6. */
  7. class AdminMenuAR extends MongoAr
  8. {
  9. public $_id;
  10. public $name = ''; //菜单名
  11. public $url = ''; //对应的链接
  12. public $sort = 1; //排序
  13. public $level = 1; //等级
  14. public $parent; //父Id
  15. public $auth_item = ''; //对应的权限名称
  16. public $status = 1; //状态
  17. public static $status_option = array(
  18. -1 => array('name' => '已删除'),
  19. 1 => array('name' => '正常', 'filter' => true)
  20. );
  21. protected $auto_fields = array('auth_item');
  22. public function __construct($scenario='insert'){
  23. parent::__construct($scenario);
  24. $this->onBeforeSave = function($event){
  25. //根据url规则得到对应的权限字符串
  26. $model = $event->sender;
  27. $url = $model->url;
  28. $route = 'no_route';
  29. $auth_item = '';
  30. if (preg_match('/(&|\?)r=([^&]+)/', $url, $matches)){
  31. $route = $matches[2];
  32. }
  33. if (($ca = Yii::app()->createController($route)) !== null){
  34. list($controller, $action) = $ca;
  35. $za = new ZAuth();
  36. $auth_item = $za->getAuthItem($controller, $action);
  37. }
  38. $model->auth_item = $auth_item;
  39. };
  40. }
  41. public static function model($className=__CLASS__)
  42. {
  43. return parent::model($className);
  44. }
  45. public function getCollectionName()
  46. {
  47. return 'admin_menu';
  48. }
  49. }