天使漫步IT工作室天使漫步IT工作室

【ACI教程】用实例学习ACI(六)


Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/u11u.com/usr/themes/wq/functions.php on line 110

Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/u11u.com/usr/themes/wq/functions.php on line 116

接第五篇的内容需要完善的功能

A、新闻栏目的添加、修改时候,如果是非根栏目,我们需要显示一下他的上级栏目。让使用者点击选择,可以自动填写上级栏目ID。

我们来分析一下该如何实现这个功能。
在前台,栏目的表现形式应该是树形。

栏目1
--栏目10
--栏目11
  --栏目110
  --栏目111
    --栏目1110
    --栏目1111

网上有很多php的树形类可以借鉴,在本文中,因为排版的原因,我计划采用分级显示模式,就是第一次显示最顶级的根,点击顶级的根,显示它下一级的根。可以发布文章的栏目和不能发布文章的栏目采用不同的显示方法。

字段is_root 和 root_id 是关键的两个字段。

  • A、初次显示:数据库的查询条件是root_id = 0(最根级目录
  • B、如果点击了根目录,如果该目录的is_root = 0,则该栏目的根目录变为选择的newstype_id;如果选择的is_root=1,则显示root_id=它的ID的栏目。余下的依次类推。

显示的设计,计划采用点击radio触发ajax的方式来获取上级根目录ID。

现在我们开始着手修改源代码。我们先来完成数据查询的工作。

我们打开aci/application/controllers/adminpanel/Newtype.php文件,这是栏目管理的控制器文件,我们在控制器Newtype中新增一个方法getroodid(id)

代码如下:

/**
* 查询根栏目
* @param int id
* @return void
*/
function getrootid($id=0)
{
    $id = intval($id);
    $data_info =$this->newstype_model->select('root_id='.$id.' or newstype_id='.$id,            ['newstype_id','type_name'],'','newstype_id','','newstype_id');
    if(!$data_info)
    {
        echo "无下级栏目";
    }
    else
    {
        foreach ($data_info as $v)
        {
            echo '<label class="radio-inline"> <input type="radio" name="set_root" id="set_root" value="'.$v['newstype_id'].'"         onclick="setrootid(this.value)"> '.$v['type_name'].'</label>';
        }
    }
} 

代码很简单,根据 newstype_id 获得栏目的ID,栏目名称,并且生成一组radio(HTML标签)

接下来比较重要的是,将这个方法添加到ACI中。
打开/aci/application/congfig/aci.php,在

'works' => true,
'moduleUrl' => 'adminpanel/newstype',
'system' => false,
'coder' => '胡子锅',
'website' => 'http://',
'moduleDetails' => 

这一组代码的最后,添加:

9 =>
array (
'folder' => 'adminpanel',
'controller' => 'newstype',
'method' => 'getrootid',
'menu_name' => '获取根id',
'caption' => '获取根id',
),  

这样,就可以把getrootid这个方法添加进来了。
我们可以在浏览器里直接打开http://localhost/aci/adminpanel/newstype/getrootid,查看方法中默认参数的显示内容。

在下一节中,我们开始view部分的修改。

本站原创,欢迎转载,转载敬请标明出处:天使漫步IT工作室 » 【ACI教程】用实例学习ACI(六)
添加新评论


Warning: Use of undefined constant php - assumed 'php' (this will throw an Error in a future version of PHP) in /www/wwwroot/u11u.com/usr/themes/wq/comments.php on line 38