国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

webman用戶模塊,添加頂部菜單了,頁面無法顯示

wadeYang

問題描述

webman用戶模塊,添加頂部菜單了,頁面無法顯示。
我開始 plugin/user/api/Template.php 的getNavData()方法加了 “問答中心”菜單,能正常顯示。后面我想改這個(gè)菜單,無論怎么改都不會變了,奇怪,是哪里有緩存嗎?



1269 4 4
4個(gè)回答

wadeYang

Event::emit('user.nav.render', $object);
還有加這個(gè)事件是啥作用,不加有什么問題嗎?

  • walkor 2023-04-24

    user.nav.render 是渲染用戶中心左側(cè)菜單,見下面例子

walkor 打賞

不要在 plugin/user/api/Template.php 里改代碼,在你的插件或者主項(xiàng)目/config/event.php配置中添加對應(yīng)的菜單.

比如
plugin/nat/config/event.php中添加如下

use plugin\foo\app\service\UserEvent;
return [
    // 當(dāng)有用戶注冊時(shí)
    'user.register' => [
        [UserEvent::class, 'onUserRegister']
    ],
    // 當(dāng)渲染用戶端導(dǎo)航菜單時(shí)
    'user.nav.render' => [
        [UserEvent::class, 'onUserNavRender']
    ],
    // 當(dāng)渲染用戶中心左側(cè)邊欄時(shí)
    'user.sidebar.render' => [
        [UserEvent::class, 'onUserSidebarRender']
    ],
];

plugin/nat/app/service/UserEvent.php

<?php

namespace plugin\nat\app\service;

use plugin\nat\app\model\NatApp;
use plugin\user\app\model\User as UserModel;
use stdClass;

/**
 * 用戶相關(guān)事件
 */
class UserEvent
{
    /**
     * 用戶注冊時(shí)
     * @return void
     */
    public function onUserRegister(UserModel $user)
    {
        $request = request();
        $host = $request->host(false);
        // 創(chuàng)建一個(gè)默認(rèn)內(nèi)網(wǎng)穿透應(yīng)用
        if (!filter_var($host, FILTER_VALIDATE_IP)) {
            $username = $user->username;
            $domain = "$username.$host";
            if (!NatApp::where('domain', $domain)->first()) {
                $app = new NatApp;
                $app->user_id = $user->id;
                $app->name = '我的應(yīng)用';
                $app->domain = $domain;
                $app->local_ip = '127.0.0.1';
                $app->local_port = 8787;
                $app->save();
            }
        }
    }

    /**
     * 當(dāng)渲染用戶端頂部導(dǎo)航菜單時(shí)
     * @param stdClass $object
     * @return void
     */
    public function onUserNavRender(stdClass $object)
    {
        $request = request();
        $path = $request ? $request->path() : '';
        // 添加內(nèi)網(wǎng)穿透自己的導(dǎo)航欄菜單
        $object->navs[] = [
            'name' => '內(nèi)網(wǎng)穿透',
            'items' => [
                ['name' => '頂部菜單1', 'url' => '/app/nat/apps', 'class' => $path === '/app/nat/apps' ? 'active' : ''],
                ['name' => '頂部菜單2', 'url' => '/app/nat/token', 'class' => $path === '/app/nat/token' ? 'active' : ''],
            ]
        ];
    }

    /**
     * 當(dāng)渲染用戶中心左側(cè)菜單時(shí)
     * @param stdClass $object
     * @return void
     */
    public function onUserSidebarRender(stdClass $object)
    {
        $request = request();
        $path = $request ? $request->path() : '';
        // 添加內(nèi)網(wǎng)穿透自己的左側(cè)用戶中心菜單
        $object->sidebars[] = [
            'name' => '內(nèi)網(wǎng)穿透',
            'items' => [
                ['name' => '用戶中心菜單1', 'url' => '/app/nat/apps', 'class' => $path === '/app/nat/apps' ? 'active' : ''],
                ['name' => '用戶中心菜單2', 'url' => '/app/nat/token', 'class' => $path === '/app/nat/token' ? 'active' : ''],
            ]
        ];
    }
}

結(jié)果類似如下
截圖

  • wadeYang 2023-04-24

    非常感謝大佬指點(diǎn),明白了

artisan

用戶模塊建議整個(gè)簡單的文檔,類似webman-admin

  • 暫無評論
zhezhebie

如果我每個(gè)左側(cè)邊欄不一樣該怎么辦呢?我看siderbar那段模板代碼是公用的。但是我想在一些控制器里面設(shè)置不同的siderbar,我定義了event,也寫了對應(yīng)的代碼,但是沒有展示,是怎么回事呢?
event代碼:

    // 當(dāng)渲染教育中心左側(cè)邊欄時(shí)
    'teach.sidebar.render' => [
        [app\event\Teach::class, 'onTeachSidebarRender'],
    ],

app\event\Teach代碼:

<?php

namespace app\event;

use stdClass;

class Teach
{
    public function onTeachSidebarRender(stdClass $object)
    {
        $request = request();
        $path = $request ? $request->path() : '';
        // 動態(tài)添加自己的導(dǎo)航欄菜單
        $object->sidebars[] = [
            'name' => '各種工具',
            'items' => [
                ['name' => '視頻工具', 'url' => '/tool/video/index', 'class' => $path === '/tool/video/index' ? 'active' : ''],
                ['name' => '教育工具', 'url' => '/tool/teach/mathHomework', 'class' => $path === '/tool/teach/mathHomework' ? 'active' : ''],
            ],
        ];
        // 一個(gè)欄目一個(gè)數(shù)組,這樣好管理
        $object->sidebars[] = [
            'name' => '測試多個(gè)菜單',
            'items' => [
                ['name' => '視頻工具', 'url' => '/tool/video', 'class' => $path === '/tool/video' ? 'active' : ''],
                ['name' => '教育工具', 'url' => '/tool/teach', 'class' => $path === '/tool/teach' ? 'active' : ''],
            ],
        ];
    }

}

然后我在控制器里面觸發(fā):

        $object = new stdClass();
        $object->sidebars = [];
        Event::emit('teach.sidebar.render', $object);

        $vars = [
            'operators' => array_keys(self::OPERATORS),
            'need' => 100,
            'sidebars' => $object->sidebars,
        ];

但是頁面沒有如期展示。

  • artisan 2024-03-07

    頁面是通過<?=plugin\user\api\Template::sidebar()?>獲取渲染菜單的,可以自定義一個(gè)TemplateSidebar類,view里根據(jù)需要調(diào)用自定義的TemplateSidebar類的對應(yīng)方法

年代過于久遠(yuǎn),無法發(fā)表回答
??