PHP code example of hwl / thinkphp-controllers-to-menu

1. Go to this page and download the library: Download hwl/thinkphp-controllers-to-menu library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hwl / thinkphp-controllers-to-menu example snippets


//加入命名空间
use Hwl\ThinkphpControllersToMenu\ControllersToMenu;

$controllerFolderPath = __DIR__ . '/Controller';
//初始化并赋值上路径
$ctm  = new ControllersToMenu($controllerFolderPath);

//获取菜单
$menu = $ctm->getMenu();

//更改命名空间,注意反斜杠的转义,命名空间的形式
$ctm->setNamespace('Home\\Controller\\');
$menu = $ctm->getMenu();

    //该版本已经增加的在注释里进行过滤,但由于继承的父类,所以仍保留这个功能,未进行测试
    /**
     * 设置过滤的类名(菜单栏)
     * @param string $className
     */
    $ctm->setNotClass($className);

    //该版本已经增加的在注释里进行过滤,但由于继承的父类及父类的方法,所以仍保留这个功能,未进行测试
    /**
     * 设置过滤的类名及方法
     * @param string $className  类名
     * @param array  $methods    方法名称数组,如何为空数组,则表示过滤整个类 array('methodName','methodName')
     */
    $ctm->setNotClassMethod($className,$methods = array());