zoukankan      html  css  js  c++  java
  • youphp学习整理

    <?php
        //后台公共模块
        //    _list        数据显示
        //    add            添加/编辑    视图
        //    insert        添加处理函数
        //    edit        添加/编辑    视图
        //    update        更新处理函数
        //    deleteall    批量删除处理函数
        //    delete        删除处理函数
        
        //基于Yourphp后台的操作写法
        //一、显示数据及搜索数据
        
        /**
         * [_list 显示数据列表]
         * @param  string  $modelname [模型名称]
         * @param  array   $map       [条件]
         * @param  string  $sortBy    [排序依据]
         * @param  boolean $asc       [默认为倒序]
         * @param  integer $listRows  [每页显示条数]
         * @return [type]             [description]
         */
        //function _list($modelname, $map = '', $sortBy = '', $asc = false ,$listRows = 15)
        class DemoAction extends AdminbaseAction{
            public function index(){
                $map['abc'] = 'demo';
                $map['cde'] = '123';
                $this->_list(MODULE_NAME,$map);//当控制器名和数据库表名一样时可以直接这样使用
                //当控制器名和数据库表名不一致时
                $this->_list('demodb');
                //当条件复杂时,我们需要组合$map即可
                $this->display();
            }
            
            //有些页面是不需要带搜索,那么可以省略index()方法
            
        }
        
        //不使用继承的写法
        function index(){
            import ( '@.ORG.Page' );
    
            $keyword=$_GET['keyword'];
            $searchtype=$_GET['searchtype'];
            $groupid =intval($_GET['groupid']);
    
            $this->assign($_GET);
            
            if(!empty($keyword) && !empty($searchtype)){
                $where[$searchtype]=array('like','%'.$keyword.'%');
            }
            if($groupid)$where['groupid']=$groupid;
    
            $user=$this->dao;
            $count=$user->where($where)->count();
            $page=new Page($count,20);
            $show=$page->show();
            $this->assign("page",$show);
            $list=$user->order('id')->where($where)
            ->limit($page->firstRow.','.$page->listRows)->select();
    
            $this->assign('ulist',$list);
            $this->display();
        }
        
        //以下为模版页上操作
        {$vo.time|toDate}
        {$vo.size|byte_format}
        //=============================
        <volist name="list" id="vo" key="k">
            {$vo['username']}
        </volist>
        //==============================
        <if condition="$vo['catid']">[<font color="green">{$categorys[$vo['catid']]['catname']}</font>]</if> 
        //当有需要读取类别名称时,使用以下方式
        //控制器中使用:
         $newcats = array();
            foreach ($group as $key => $value) {
                $newcats[$value['id']]['id']    = $value['id'];
                $newcats[$value['id']]['tname'] = $value['tname'];
                $newcats[$value['id']]['tamount'] = $value['tamount'];
            }
            $this->assign('newcats',$newcats);
        //模版上使用:
        <td align="center">
                    {$newcats[$vo['tid']]['tname']}
                  </td>
                  <td align="center">
                    {$newcats[$vo['tid']]['tamount']}
                  </td>
  • 相关阅读:
    LiveData讲解
    Android分区存储相关
    十:存储过程和函数
    九:事务
    八:约束 和分页
    七:常见的数据类型
    六:创建和管理表
    五:SQL常见的函数
    四:SQL基本语句
    二:MYSQL 数据库的安装和常见一些命名
  • 原文地址:https://www.cnblogs.com/mssql8/p/3984636.html
Copyright © 2011-2022 走看看