admin 发表于 2023-3-12 14:51:26

ModStart 中HasAdminQuickCRUD 的功能使用解析

<p style="box-sizing:border-box;line-height:inherit;margin-top:22px;margin-bottom:22px;color:rgb(37,41,51);font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';font-size:16px;white-space:normal;background-color:rgb(255,255,255);"><code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">HasAdminQuickCRUD</code> 是<code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">ModStart</code> 中的一个增删改查语法糖,用于快速构建一个增删改查页面。使用方式通常如下所示:</p>

<pre>class NewsController extends Controller{
    use HasAdminQuickCRUD;
    protected function crud(AdminCRUDBuilder $builder)
    {
        $builder            ->init('news')
            ->field(function ($builder) {
                $builder->id('id', 'ID');
                $builder->text('title', '名称');
            })
            ->title('新闻资讯');
    }
}</pre>

<p style="box-sizing:border-box;line-height:inherit;margin-top:22px;margin-bottom:22px;color:rgb(37,41,51);font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';font-size:16px;white-space:normal;background-color:rgb(255,255,255);">该文件位于 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">vendor/modstart/modstart/src/Admin/Concern/HasAdminQuickCRUD.php</code> 。</p>

<p style="box-sizing:border-box;line-height:inherit;margin-top:22px;margin-bottom:22px;color:rgb(37,41,51);font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';font-size:16px;white-space:normal;background-color:rgb(255,255,255);">可以看到该 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">Trait</code> 中注册了 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">grid、form、detail</code> 三个方法,用于自动构建表格、表单、详情三个页面的内容。</p>

<p style="box-sizing:border-box;line-height:inherit;margin-top:22px;margin-bottom:22px;color:rgb(37,41,51);font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';font-size:16px;white-space:normal;background-color:rgb(255,255,255);">同时,该 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">Trait</code> 又引入了 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">HasAdminCRUD</code>,用于引入表格、表单、详情的处理过程。</p>

<pre>trait HasAdminCRUD{
    use HasPageTitleInfo;
    use HasAdminGrid;
    use HasAdminDetail;
    use HasAdminForm;
}</pre>

<p style="box-sizing:border-box;line-height:inherit;margin-top:22px;margin-bottom:22px;color:rgb(37,41,51);font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';font-size:16px;white-space:normal;background-color:rgb(255,255,255);">通过通过引入的 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">HasAdminQuickCRUD → HasAdminCRUD → HasAdminGrid</code> ,声明了整个增删改查的入口方法 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">index</code>。</p>

<p style="box-sizing:border-box;line-height:inherit;margin-top:22px;margin-bottom:22px;color:rgb(37,41,51);font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';font-size:16px;white-space:normal;background-color:rgb(255,255,255);">通过通过引入的 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">HasAdminQuickCRUD → HasAdminCRUD → HasAdminDetail</code> ,声明了整个增删改查的入口方法 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">show</code>。</p>

<p style="box-sizing:border-box;line-height:inherit;margin-top:22px;margin-bottom:22px;color:rgb(37,41,51);font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';font-size:16px;white-space:normal;background-color:rgb(255,255,255);">通过通过引入的 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">HasAdminQuickCRUD → HasAdminCRUD → HasAdminForm</code> ,声明了整个增删改查的入口方法 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">add、edit、delete</code> 方法。</p>

<p style="box-sizing:border-box;line-height:inherit;margin-top:22px;margin-bottom:22px;color:rgb(37,41,51);font-family:'-apple-system', BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';font-size:16px;white-space:normal;background-color:rgb(255,255,255);">通过 <code style="box-sizing:border-box;font-family:Menlo, Monaco, Consolas, 'Courier New', monospace;font-size:0.87em;border-radius:2px;background-color:rgb(255,245,245);color:rgb(255,80,44);padding:0.065em 0.4em;">HasAdminQuickCRUD</code> 来开发页面,短短几行代码,可以高效的完成一个增删改查页面,同时对于字段的扩展也有一定的灵活性,是官方使用频率非常高的一个功能。</p>
页: [1]
查看完整版本: ModStart 中HasAdminQuickCRUD 的功能使用解析