您的位置:首页 > 其它

项目中的一些常用的知识点总结

2016-11-02 11:35 423 查看

1、对于删除的多个列表选项前台的传参

(用jquery方法获得多个选项的id)

//jQuery代码

$(function(){

    //给删除按钮添加点击事件

    $('#btndel').on('click',function(){

        //获取复选框的id值

        var id = $(':checkbox:checked');    //jQuery对象,类数组的对象

        var ids = '';   //要求ids的形式是 1,2,3,4,5

        for(var i = 0;i < id.length;i++){

            ids = ids + id[i].value + ',';

        }

        //剔除右边的逗号

        ids = ids.substring(0,ids.length-1);

        //跳转

        window.location.href = '__CONTROLLER__/del/ids/' + ids; //Tp框架中的写法

    });

    //给编辑按钮添加点击事件

    $('#btnedit').on('click',function(){

        //获取复选框的id值

        var id = $(':checkbox:checked').val();

        //跳转

        window.location.href = '__CONTROLLER__/edit/id/' + id;

    });

});

2、无限极分类

function getTree($list,$pid=0,$level=0) {
static $tree = array();
foreach($list as $row) {
if($row['pid']==$pid) {
$row['level'] = $level;
$tree[] = $row;
getTree($list, $row['id'], $level + 1);
}
}
return $tree;

}

3、在同一张表中查询父级的字段名

foreach ($data as $key => $value) {
#二次查询,通过查询pid所对应的数据信息,获取其中的name字段
$info = $model -> find($value['pid']);
#获取其中的name字段存到$data中去
$data[$key]['parentName'] = $info['name'];
}

4、多条件搜索框查询

$where
= '2 > 1';
 if ($_POST) {
 if ($_POST['category'])
{
 $where
.= " AND category_id = '{$_POST['category']}'";
 }
 if ($_POST['status'])
{
 $where
.= " AND status = '{$_POST['status']}'";
 }
 if (isset($_POST['istop']))
{
 $where
.= " AND top = '{$_POST['istop']}'";
 }
 if ($_POST['search'])
{
 $where
.= " AND title LIKE '%{$_POST['search']}%'";
 }
 }
/*
 $pager = new Pager(总的记录数, 每页记录数, 当前页数, 'php入口脚本index.php', array(参数
 'a' => 'index',
 'c' => 'product',
 ));
 
 $pagerHtml = $pager->showPage();
 */
 $page
= isset($_GET['page']) ?
$_GET['page'] :
1;
 $pageSize
= 1;
 $pager
= new
Pager(ArticleModel::create()->count(),
$pageSize, $page,
'index.php',
array(
 'p'
=>
'backend',
 'c'
=>
'Article',
 'a'
=>
'getList',
 ));
 // 获取分页按钮
 $pageButtons
= $pager->showPage();
 
 $start
= ($page
- 1)
* $pageSize;
 $articles
= ArticleModel::create()->getAllWithJoin($where,
'id ASC',
$start, $pageSize);
 $categories
= CategoryModel::create()
 ->limitlessLevelCategory(
 CategoryModel::create()->findAll()
 );
 $this->loadHtml('article/getList',
array(
 'articles'
=>
$articles,
 'categories'
=>
$categories,
 'pageButtons'
=>
$pageButtons,
 ));
 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: