Skip to content

自定义视图

模板引擎范例

Controller文件

php
<?php namespace LinAdmin\example;

use app\model\Newplugin;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use LinAdmin\controller\CCustomController;
use LinAdmin\controller\CNewController;
use LinAdmin\example\Model\ExternalMock;

class CExampleCustomController extends CCustomController
{
    protected $header = '自定义视图';

    protected function getData()
    {
        return [
            "llm_model_list" => "abc",
            "aiperson_list" => "eee",
            "current_llm" => "gpt-3.5-turbo",
        ];
    }
    protected function getView()
    {
        return "application/plugins/test/views/test123";
    }

}

twig文件

html
<p style="font-weight: 700;">hello {{llm_model_list}}</p>

vue2范例

Controller文件

php
<?php

namespace LinAdmin\example;

use app\model\Newplugin;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use LinAdmin\controller\CCustomController;
use LinAdmin\controller\CNewController;
use LinAdmin\example\Model\ExternalMock;

class CExampleCustomController extends CCustomController
{
    protected $header = '自定义视图';
    protected $is_vue = true;

    protected function getData()
    {
        return [
            "llm_model_list" => "abc",
            "aiperson_list" => "eee",
            "current_llm" => "gpt-3.5-turbo",
            "count" => "100",
        ];
    }
    protected function getView()
    {
        return "application/plugins/test/views/test123";
    }
    public function render()
    {
        return parent::render();
    }

}

twig文件

html

<p>count:{{ count }}</p>
<el-input v-model="count" placeholder="请输入"></el-input>
<script>
    var app = new Vue({
        el: '#app',
        data: __DATA__,
        methods: {
            test() {
                alert("hello");
            }
        }
    })
</script>