CMS:eyoucms 项目需求:一篇文档对应多个栏目 解决思路: 后端:在文档数据表添加一个附属栏目字段fslm_id,在文档编辑,添加页面添加附属栏目选项,获取当前模型对应的所有栏目放入到附属栏目选项中。
后台修改:
1.添加表字段 文档存储数据表:archives 添加数据字段:fslm_id
2.文章文档编辑 控制器:app>admin>controller>Article.php 列表视图:app>admin>template>article>index.htm 编辑视图:app>admin>template>article>edit.htm 添加视图:app>admin>template>article>add.htm
3.产品文档编辑 控制器:app>admin>controller>Product.php 列表视图:app>admin>template>product>index.htm 编辑视图:app>admin>template>product>edit.htm 添加视图:app>admin>template>product>add.htm
// /5.5版本后台数据列表*/ //
<dl class="row">
<dt class="tit">
<label for="title"><em>*</em>附属栏目</label>
</dt>
<dd class="opt">
<select multiple class="form-control" name="fslm_id[]" id="fslm_id">
{$arctype_html}
</select>
</dd>
</dl>
Article.php
public function index(){
$fslmcx = Db::name('archives')->select();
foreach($fslmcx as $k => $y){
if($y['fslm_id'] != false){
$fslm_id = unserialize($y['fslm_id']);
foreach($fslm_id as $tyid){
if($typeid == $tyid){
if(!($typeid == $y['typeid'])){
$newids = [$y['aid']];
$row_fslm = Db::name('archives')
->field($fields)
->alias('a')
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
->where('a.aid', 'in', $newids)
->getAllWithIndex('aid');
$fslm_column = Db::name('arctype')->where('id',$y['typeid'])->select();
$y['typename'] = $fslm_column['0']['typename'];
$y['arcurl'] = get_arcurl($row_fslm[$y['aid']]);
$list[] = $y;
}
}
}
}
}
}
// /5.5版本前端数据获取*/ // 前端修改: 根据项目需求:首页有多个分类栏目需要展示附属栏目文档 修改文件: 视图:app>template>pc>index.htm
{php}
$fslmd = [];
foreach ($fslmcx as $ks => $wendang){
if($wendang['fslm_id'] != false){
$fslm_id = unserialize($wendang['fslm_id']);
foreach($fslm_id as $fskms){
if($fskms == $field3['typeid']){
if(!($field3['typeid'] == $wendang['typeid'])){
// 获取文档URL
$wendang['arcurl'] = url('home/View/index','aid='.$wendang['aid']);
$fslmd[] = $wendang;
}
}
}
}
}
{/php}
{volist name="fslmd" id="vo" offset="0" length='6'}
<li class="tupian_Column_p cpbk_changdu">
<a href="{$vo.arcurl}"><div><img src="{$vo.litpic}" alt=""></div></a>
<a href="{$vo.arcurl}"><p>{$vo.title}</p></a>
</li>
{/volist}
控制器:app>home>controller>index.php
$fslmcx = Db::name('archives')->where('is_recom', '1')->where('lang', 'cn')->select();
$this->assign('fslmcx', $fslmcx);
*5.6版本后不需要另外单独调用前端数据,只需把后台数据调用出来方便后台管理 /**********************/ /5.6版本后台数据列表/ /**********************/
$fslmcx = Db::name('archives')->select();
foreach($fslmcx as $k => $chanping){
if(!empty($chanping['stypeid'])){
$chanping['stypeid'] = explode(',',$chanping['stypeid']);
foreach($chanping['stypeid'] as $kstypeid => $fushulm){
if($fushulm == $typeid){
$newids = [$chanping['aid']];
$fields = "b.*, a.*, a.aid as aid";
$row_fslm = Db::name('archives')
->field($fields)
->alias('a')
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
->where('a.aid', 'in', $newids)
->getAllWithIndex('aid');
$fslm_column = Db::name('arctype')->where('id',$chanping['typeid'])->select();
$chanping['typename'] = $fslm_column['0']['typename'];
$chanping['arcurl'] = get_arcurl($row_fslm[$chanping['aid']]);
$list[] = $chanping;
}
}
}
}
public function edit(){
$fslm_id = serialize($post['fslm_id']);
$newData = array(
'fslm_id' => $fslm_id,
);
}
|