多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 关联版式 关联版式 文件路径:shop/controllers/Seller/GoodsCtl.php; ##### 1、版式显示(format()) 后台数据获取: ``` <pre class="calibre14">``` $format_rows <span class="token">=</span> $Goods_FormatModel<span class="token">-</span><span class="token">></span><span class="token3">getFormatList</span><span class="token1">(</span>$cond_row<span class="token1">,</span> <span class="token3">array</span><span class="token1">(</span><span class="token1">)</span><span class="token1">,</span> $page<span class="token1">,</span> $rows<span class="token1">)</span><span class="token1">;</span> ``` ``` 前台显示: ``` <pre class="calibre14">``` <span class="token"><</span><span class="token">?</span>php foreach <span class="token1">(</span>$data as $key <span class="token">=</span><span class="token">></span> $value<span class="token1">)</span> <span class="token1">{</span> <span class="token">?</span><span class="token">></span> <span class="token"><</span>tr<span class="token">></span> <span class="token"><</span>td class<span class="token">=</span><span class="token4">"tl"</span><span class="token">></span> <span class="token"><</span>label class<span class="token">=</span><span class="token4">"checkbox"</span><span class="token">></span><span class="token"><</span>input class<span class="token">=</span><span class="token4">"checkitem"</span> type<span class="token">=</span><span class="token4">"checkbox"</span> name<span class="token">=</span><span class="token4">"chk[]"</span> value<span class="token">=</span><span class="token4">"<?= $value['id'] ?>"</span><span class="token">/</span><span class="token">></span><span class="token"><</span><span class="token">/</span>label<span class="token">></span> <span class="token"><</span><span class="token">?</span><span class="token">=</span> $value<span class="token1">[</span><span class="token4">'name'</span><span class="token1">]</span> <span class="token">?</span><span class="token">></span> <span class="token"><</span><span class="token">/</span>td<span class="token">></span> <span class="token"><</span>td<span class="token">></span><span class="token"><</span><span class="token">?</span>php <span class="token3">print</span><span class="token1">(</span>$value<span class="token1">[</span><span class="token4">'position_name'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">;</span> <span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>td<span class="token">></span> <span class="token"><</span>td<span class="token">></span> <span class="token"><</span>span class<span class="token">=</span><span class="token4">"edit"</span><span class="token">></span><span class="token"><</span>a href<span class="token">=</span><span class="token4">"<?php echo Yf_Registry::get('url'); ?>?ctl=Seller_Goods&met=format&act=edit&id=<?= $value['id']; ?>"</span><span class="token">></span><span class="token"><</span>i class<span class="token">=</span><span class="token4">"iconfont icon-zhifutijiao"</span><span class="token">></span><span class="token"><</span><span class="token">/</span>i<span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">__</span><span class="token1">(</span><span class="token4">'编辑'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>a<span class="token">></span><span class="token"><</span><span class="token">/</span>span<span class="token">></span> <span class="token"><</span>span class<span class="token">=</span><span class="token4">"del"</span><span class="token">></span><span class="token"><</span>a data<span class="token">-</span>param<span class="token">=</span><span class="token4">"{'id':'<?= $value['id']; ?>','ctl':'Seller_Goods','met':'deleteGoodsFormat'}"</span> href<span class="token">=</span><span class="token4">"javascript:void(0)"</span><span class="token">></span><span class="token"><</span>i class<span class="token">=</span><span class="token4">"iconfont icon-lajitong"</span><span class="token">></span><span class="token"><</span><span class="token">/</span>i<span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">__</span><span class="token1">(</span><span class="token4">'删除'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>a<span class="token">></span><span class="token"><</span><span class="token">/</span>span<span class="token">></span> <span class="token"><</span><span class="token">/</span>td<span class="token">></span> <span class="token"><</span><span class="token">/</span>tr<span class="token">></span> <span class="token"><</span><span class="token">?</span>php <span class="token1">}</span><span class="token">?</span><span class="token">></span> ``` ``` ##### 2、新增版式 (format()) 参数:act=add 视图文件: ``` <pre class="calibre14">``` $this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">setMet</span><span class="token1">(</span><span class="token4">'addformat'</span><span class="token1">)</span><span class="token1">;</span> ``` ``` 提交表单: ``` <pre class="calibre14">``` $<span class="token1">(</span><span class="token4">'#form'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">validator</span><span class="token1">(</span><span class="token1">{</span> ignore<span class="token1">:</span> <span class="token4">':hidden'</span><span class="token1">,</span> theme<span class="token1">:</span> <span class="token4">'yellow_right'</span><span class="token1">,</span> timely<span class="token1">:</span> <span class="token6">1</span><span class="token1">,</span> stopOnError<span class="token1">:</span> <span class="token6">false</span><span class="token1">,</span> rules<span class="token1">:</span> <span class="token1">{</span> <span class="token1">}</span><span class="token1">,</span> fields<span class="token1">:</span> <span class="token1">{</span> <span class="token4">'name'</span><span class="token1">:</span> <span class="token4">'required;'</span> <span class="token1">}</span><span class="token1">,</span> valid<span class="token1">:</span><span class="token2">function</span><span class="token1">(</span>form<span class="token1">)</span><span class="token1">{</span> <span class="token5">//表单验证通过,提交表单</span> $<span class="token1">.</span><span class="token3">ajax</span><span class="token1">(</span><span class="token1">{</span> url<span class="token1">:</span> ajax_url<span class="token1">,</span> data<span class="token1">:</span>$<span class="token1">(</span><span class="token4">"#form"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">serialize</span><span class="token1">(</span><span class="token1">)</span><span class="token1">,</span> type<span class="token1">:</span><span class="token4">"POST"</span><span class="token1">,</span> success<span class="token1">:</span><span class="token2">function</span><span class="token1">(</span>a<span class="token1">)</span><span class="token1">{</span> <span class="token2">if</span><span class="token1">(</span>a<span class="token1">.</span>status <span class="token">==</span> <span class="token6">200</span><span class="token1">)</span> <span class="token1">{</span> Public<span class="token1">.</span><span class="token3">tips</span><span class="token1">(</span><span class="token1">{</span> content<span class="token1">:</span> <span class="token4">"<?=__('操作成功'); ?>"</span><span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> <span class="token2">if</span> <span class="token1">(</span>opener<span class="token1">)</span> <span class="token1">{</span> opener<span class="token1">.</span><span class="token3">addLayout</span><span class="token1">(</span><span class="token1">{</span> id<span class="token1">:</span> a<span class="token1">.</span>data<span class="token1">.</span>id<span class="token1">,</span> name<span class="token1">:</span> $<span class="token1">(</span><span class="token4">"#title"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">val</span><span class="token1">(</span><span class="token1">)</span><span class="token1">,</span> position<span class="token1">:</span> $<span class="token1">(</span><span class="token4">"select[name=\"position\"]"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">val</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> window<span class="token1">.</span><span class="token3">close</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span> location<span class="token1">.</span>href<span class="token">=</span>SITE_URL <span class="token">+</span> <span class="token4">"?ctl=Seller_Goods&met=format&typ=e"</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span> Public<span class="token1">.</span><span class="token3">tips</span><span class="token1">(</span><span class="token1">{</span> content<span class="token1">:</span> <span class="token4">"<?=__('操作失败'); ?>"</span><span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> ``` ``` ##### 3、版式编辑(format()) 参数:act = edit 视图文件: ``` <pre class="calibre14">``` $this<span class="token">-</span><span class="token">></span>view<span class="token">-</span><span class="token">></span><span class="token3">setMet</span><span class="token1">(</span><span class="token4">'addformat'</span><span class="token1">)</span><span class="token1">;</span> ``` ``` 表单提交与2、版式添加中表单提交相同 ##### 4、版式删除() ``` <pre class="calibre15">``` <span class="token"><</span>span class<span class="token">=</span><span class="token4">"del"</span><span class="token">></span><span class="token"><</span>a data<span class="token">-</span>param<span class="token">=</span><span class="token4">"{'id':'<?= $value['id']; ?>','ctl':'Seller_Goods','met':'deleteGoodsFormat'}"</span> href<span class="token">=</span><span class="token4">"javascript:void(0)"</span><span class="token">></span><span class="token"><</span>i class<span class="token">=</span><span class="token4">"iconfont icon-lajitong"</span><span class="token">></span><span class="token"><</span><span class="token">/</span>i<span class="token">></span><span class="token"><</span><span class="token">?</span><span class="token">=</span><span class="token3">__</span><span class="token1">(</span><span class="token4">'删除'</span><span class="token1">)</span><span class="token">?</span><span class="token">></span><span class="token"><</span><span class="token">/</span>a<span class="token">></span><span class="token"><</span><span class="token">/</span>span<span class="token">></span> ``` ```