像 Discuz!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 这种实现主题切换的功能怎么实现的?

laravel 有类型好用的库吗?这种功能有啥好的思路?

by JeffreyBool blog :point_right: link
JeffreyBool
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
Summer
最佳答案

如果控制器里统一都使用 view() 来加载视图,可以参考 vendor/laravel/framework/src/Illuminate/Foundation/helpers.php 里的:

if (! function_exists('view')) {
    /**
     * Get the evaluated view contents for the given view.
     *
     * @param  string  $view
     * @param  \Illuminate\Contracts\Support\Arrayable|array   $data
     * @param  array   $mergeData
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
     */
    function view($view = null, $data = [], $mergeData = [])
    {
        $factory = app(ViewFactory::class);

        if (func_num_args() === 0) {
            return $factory;
        }

        return $factory->make($view, $data, $mergeData);
    }
}

你改成:

function view($view = null, $data = [], $mergeData = [])
    {
        $factory = app(ViewFactory::class);

        if (func_num_args() === 0) {
            return $factory;
        }

        $view = config('theme.name') . '.' . $view;

        return $factory->make($view, $data, $mergeData);
    }
4年前 评论
JeffreyBool (楼主) 4年前
讨论数量: 4

:joy: 去翻翻 discuz 的源码就知道了..

4年前 评论
JeffreyBool (楼主) 4年前
sodasix (作者) 4年前
Summer

如果控制器里统一都使用 view() 来加载视图,可以参考 vendor/laravel/framework/src/Illuminate/Foundation/helpers.php 里的:

if (! function_exists('view')) {
    /**
     * Get the evaluated view contents for the given view.
     *
     * @param  string  $view
     * @param  \Illuminate\Contracts\Support\Arrayable|array   $data
     * @param  array   $mergeData
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
     */
    function view($view = null, $data = [], $mergeData = [])
    {
        $factory = app(ViewFactory::class);

        if (func_num_args() === 0) {
            return $factory;
        }

        return $factory->make($view, $data, $mergeData);
    }
}

你改成:

function view($view = null, $data = [], $mergeData = [])
    {
        $factory = app(ViewFactory::class);

        if (func_num_args() === 0) {
            return $factory;
        }

        $view = config('theme.name') . '.' . $view;

        return $factory->make($view, $data, $mergeData);
    }
4年前 评论
JeffreyBool (楼主) 4年前

直接动态引入不同主题的 CSS 即可。

4年前 评论

github上有很多主题扩展啊,随便用一个都行,https://github.com/FaCuZ/laravel-theme, 我一般用这个,功能足够用了

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!