• 8.6 缓存,session和cookie,分页和文件上传


    <?php
         namespace appdemocontroller;
         use thinkController;
         use thinkCache;
         
         class Huancun extends Controller{
             public function test(){
                 //$data = db('student')->select();
                 //使用系统类
                 //Cache::set('studentData',$data,300);
                 //使用助手函数
                 //cache('studentData',$data,300);
                 //return view();
                 /*if($data = cache('studentData')){
                
                }else{
                    $data = db('student')->select();
                    
                    cache('studentData', $data, 30);
                }*/
                //dump($data);
                $data = db('student')->paginate(3);
                $this->assign('data',$data);    
                return view();
             }
             public function uploadsView(){
                 return view();
             }
             public function uploads(){
                 $request = request();
                 $file = $request->file('upfile');
                 $info = $file->move(ROOT_PATH.'public/uploads');
                 if($info){
                     echo $info->getExtension();
                     echo $info->getSaveName();
                     echo $info->getFilename();
                 }else{
                     //
                     echo $file->getError();
                 }
             }
         }
         
         
         
         
         
         
         //session
       /* namespace appdemocontroller;
        
        use thinkController;
        use thinkSession;
         class Index extends Controller{
            public function setSession(){
                //设置session
                Session::set('name','zhangsan');
                session('name','zhangsan');
            }
            public function getSession(){
                //读取session
                return Session::get('name');
                return session('name');
            }
            public function pSession(){
                //判断session存不存在
                return Session::has('name');
            }
            public function delSession(){
                //删除session
                Session::delete('name');
                session('name',null);
            }
        }*/
        //Cookie
        /*namespace appdemocontroller;
        
        use thinkController;
        use thinkCookie;
        class Index extends Controller{
            public function setcookie(){
                //设置cookie
                Cookie::set('name','zhangsan',3600);
                cookie('name','zhangsan',3600);
            }
            public function getcookie(){
                //读取cookie
                return Cookie::get('name');
                return cookie('name');
            }
            public function pcookie(){
                //判断cookie存不存在
                return Cookie::has('name');
            }
            public function delcookie(){
                //删除cookie
                Cookie::delete('name');
                cookie('name',null);
            }
        }*/
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
            <table border="" cellspacing="" cellpadding="">
                <tr>
                    <td>学号</td>
                    <td>名字</td>
                    <td>班级</td>
                </tr>
                {volist name='data' id='value'}
                    <tr>
                        <td>{$value.Sno}</td>
                        <td>{$value.Sname}</td>
                        <td>{$value.Class}</td>
                    </tr>
                {/volist}
            </table>
            {$data->render()}
        </body>
    </html>
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
            <form action="{:url('uploads')}" method="post" enctype="multipart/form-data">
                <input type="file" name="upfile" id="upfile" value="" >
                <input type="submit" value="提交"/>
            </form>
        </body>
    </html>
  • 相关阅读:
    springboot2 + prometheus + grafana 监控整合
    vs code 快捷键总结
    java8 concurrecy
    java8 localdatetime timestamp 转换
    有意思的网站
    评价搜索引擎质量
    转载一篇文章
    csdn 站点使用
    百度站点平台
    好的文章聚合站点
  • 原文地址:https://www.cnblogs.com/sunhao1987/p/9434940.html
Copyright © 2020-2023  润新知