43 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
		
		
			
		
	
	
			43 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								namespace app\widget\manager;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use app\model\{Category, AuthRule};
							 | 
						||
| 
								 | 
							
								use think\facade\View;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class Crumbs
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    public function index()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $request = request();
							 | 
						||
| 
								 | 
							
								        $controller = strtolower($request->controller());
							 | 
						||
| 
								 | 
							
								        $action = strtolower($request->action());
							 | 
						||
| 
								 | 
							
								        $controller = str_replace('manager.', '', $controller);
							 | 
						||
| 
								 | 
							
								        $name = $controller . '/' . $action;
							 | 
						||
| 
								 | 
							
								        if($action == 'index'){
							 | 
						||
| 
								 | 
							
								            $rule = AuthRule::getByTwoName($name, $controller);
							 | 
						||
| 
								 | 
							
								        }else{
							 | 
						||
| 
								 | 
							
								            $rule = AuthRule::getByName($name);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        $parent = [];
							 | 
						||
| 
								 | 
							
								        if(!empty($rule) && $rule['parent_id']){
							 | 
						||
| 
								 | 
							
								            $parent = AuthRule::getById($rule['parent_id']);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        $cateCrumbs = [];
							 | 
						||
| 
								 | 
							
								        $isContent = false;
							 | 
						||
| 
								 | 
							
								        if($controller == 'content') {
							 | 
						||
| 
								 | 
							
								            $isContent = true;
							 | 
						||
| 
								 | 
							
								            $categoryId = $request->param('category_id', 0);
							 | 
						||
| 
								 | 
							
								            if (is_numeric($categoryId) && $categoryId > 0) {
							 | 
						||
| 
								 | 
							
								                $cateCrumbs = Category::getCatesCrumbs($categoryId);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $data = [
							 | 
						||
| 
								 | 
							
								            'rule' => $rule,
							 | 
						||
| 
								 | 
							
								            'parent' => $parent,
							 | 
						||
| 
								 | 
							
								            'isContent' => $isContent,
							 | 
						||
| 
								 | 
							
								            'cateCrumbs' => $cateCrumbs
							 | 
						||
| 
								 | 
							
								        ];
							 | 
						||
| 
								 | 
							
								        return View::assign($data)->fetch('manager/widget/crumbs');
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |