fix active menu
This commit is contained in:
		
							
								
								
									
										49
									
								
								kernel/services/MenuService.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								kernel/services/MenuService.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| <?php | ||||
|  | ||||
| namespace kernel\services; | ||||
|  | ||||
| use app\helpers\Debug; | ||||
| use kernel\models\Menu; | ||||
| use kernel\Request; | ||||
|  | ||||
| class MenuService | ||||
| { | ||||
|     public static function getChild(int $id) | ||||
|     { | ||||
|         $collection = Menu::where("parent_id", $id)->get(); | ||||
|         if (!$collection->isEmpty()){ | ||||
|             return $collection; | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     public static function hasActiveChild(int $id): bool | ||||
|     { | ||||
|         $child = self::getChild($id); | ||||
|         if (!$child->isEmpty()){ | ||||
|             foreach ($child as $item){ | ||||
| //                if ($item->url === \kernel\Request::getUrlPath()){ | ||||
| //                    return true; | ||||
| //                } | ||||
|                 if (strripos(Request::getUrlPath(), $item->url) !== false) { | ||||
|                     return true; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     public static function getActiveStatus($url) | ||||
|     { | ||||
|         if ($url === Request::getUrlPath()){ | ||||
|             return true; | ||||
|         } else { | ||||
|             if (strripos(\kernel\Request::getUrlPath(), ($url . "/page")) !== false) { | ||||
|                 return true; | ||||
|             } | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user