林小陌

林小陌

这家伙有点懒,还没写个性签名!

  • 财富值75
  • 威望值10
  • 总积分195

个人信息

  • 赞了回答

    文件上传 多文件

    `控制器
     yii\web\UploadedFile;
     $model->file = UploadedFile::getInstances($model, 'file');
            $file_arr = array();
            foreach($model -> file as $file){
                $file_name = 'uploads/' . time() . rand(111111,999999).'.'. $file->extension;
                $file -> saveAs($file_name);
                $file_arr[] = $file_name;
            }
     视图:
    <?php
     use yii\widgets\ActiveForm;
     use yii\helpers\Html;
    ?>
     <?php $form=ActiveForm::begin(['options'=>['enctype'=>'multipart/form-data'],'action'=>   ['news/upfile'],'method'=>'post',])?>
     <?=$form->field($model,'file[]')->fileInput(['multiple'=>true])?>
     <?php echo Html::submitButton('提交',['class' => 'btn btn-primary'])?>
    <?php ActiveForm::end();?>
    

    `

  • 赞了回答

    dao模式分页,我看了好多教程,他们用的那个类,在框架里面根本找不到。

  • 回复了 的回答

    <?php

    namespace frontend\controllers;
    use yii\web\controller;
    use yii;
    class DataController extends Controller{

    public function actionIndex(){
        $db = new \yii\db\Connection([
        'dsn' => 'mysql:host=localhost;dbname=aaa',
         'username' => 'root',
         'password' => '',
        ]);
    
        $db->open();
        //查询
        $command = $db->createCommand('SELECT * FROM zhuce')->queryAll();
        //修改
        //$command = $db->createCommand("UPDATE zhuce SET uname='qweqdqdq' WHERE id=2")->execute();
       	//删除
       	//$command = $db->createCommand("delete from zhuce where id =2")->execute();
       	//添加
       	//$command = $db->createCommand("insert into zhuce (uname,pwd)values('ok','123')")->execute();
       	//添加多条
       	//$command = $db->createCommand()->batchInsert('zhuce', ['uname', 'pwd'], [['Tom', 30],['Jane', 20],['Linda', 25]])->execute();
    $session = Yii::$app->session;
    
    }
    

    }

    ?>

    DAO模式没有很会用,感谢。
    不知道你会不会DAO模式的分页呢?

  • 关注了
  • 回复了 的回答

    文件上传 多文件

    `控制器
     yii\web\UploadedFile;
     $model->file = UploadedFile::getInstances($model, 'file');
            $file_arr = array();
            foreach($model -> file as $file){
                $file_name = 'uploads/' . time() . rand(111111,999999).'.'. $file->extension;
                $file -> saveAs($file_name);
                $file_arr[] = $file_name;
            }
     视图:
    <?php
     use yii\widgets\ActiveForm;
     use yii\helpers\Html;
    ?>
     <?php $form=ActiveForm::begin(['options'=>['enctype'=>'multipart/form-data'],'action'=>   ['news/upfile'],'method'=>'post',])?>
     <?=$form->field($model,'file[]')->fileInput(['multiple'=>true])?>
     <?php echo Html::submitButton('提交',['class' => 'btn btn-primary'])?>
    <?php ActiveForm::end();?>
    

    `

    但是假如我要循环入库,是不是要重新创建对象

  • 回复了 的回答
            ```
     首先引入
               yii\data\Pagination;
               还有各种模型
            控制器:
                new一个AR对象出来
                $search = Yii::$app->request->get('search_key');
                $where = '1 = 1';
                    if ($search) {
                        $where .= ' and JName like "%'.$search.'%"';
                    }
                    $pageArr = $model -> find()->where($where);
                    $pagination = new Pagination(['totalCount' => $pageArr -> count(),'pageSize'=>'3']);
                    $result = $pageArr ->join('INNER JOIN', 'recruit_enterprise','recruit_enterprise.CId = recruit_job.CId')
                                       ->select('*')
                                       ->offset($pagination ->offset)
                                       ->limit($pagination ->limit)
                                       ->where($where)
                                       ->asArray()
                                       ->all();
    
                    return $this -> render('job_list',
                        ['result' => $result,
                        'pagination' => $pagination,
                        ]
                    );
    
    
    
          以上是本人个人代码    仅供参考
    

    你发的这个很实用,谢谢你

  • yii2 框架中的一些常用操作,望各位大神指导。

助理 等级规则
195/200
资料完整度
20/100
用户活跃度
0/100

Ta的关注

6

Ta的粉丝

7

Ta的访客

13