草庐IT

yii2-codeception

全部标签

php - 使用 ActiveRecord 和 Yii2 记录实际的 SQL 查询?

我这样做:$students=Student::find()->all();return$this->render('process',array('students'=>$students));然后在View中:foreach($studentsas$student){echo$student->name.', ';echo$student->getQuizActivitiesCount();?>我想查看正在执行的sql查询。一个学生“有很多”测验事件,查询执行得很好,但我需要查看原始SQL。这可能吗? 最佳答案 方法一

php - 使用 ActiveRecord 和 Yii2 记录实际的 SQL 查询?

我这样做:$students=Student::find()->all();return$this->render('process',array('students'=>$students));然后在View中:foreach($studentsas$student){echo$student->name.', ';echo$student->getQuizActivitiesCount();?>我想查看正在执行的sql查询。一个学生“有很多”测验事件,查询执行得很好,但我需要查看原始SQL。这可能吗? 最佳答案 方法一

php - 如何在 yii 中以 json 格式(应用程序/json)获得响应?

如何在yii中获取json格式的响应(application/json)? 最佳答案 对于Yii1:在您的(基本)Controller中创建此函数:/***ReturndatatobrowserasJSONandendapplication.*@paramarray$data*/protectedfunctionrenderJSON($data){header('Content-type:application/json');echoCJSON::encode($data);foreach(Yii::app()->log->rout

php - 如何在 yii 中以 json 格式(应用程序/json)获得响应?

如何在yii中获取json格式的响应(application/json)? 最佳答案 对于Yii1:在您的(基本)Controller中创建此函数:/***ReturndatatobrowserasJSONandendapplication.*@paramarray$data*/protectedfunctionrenderJSON($data){header('Content-type:application/json');echoCJSON::encode($data);foreach(Yii::app()->log->rout

mysql - 如何在 Yii2 中进行批量数据库插入?

我想知道你是如何在Yii2中做一个批量数据库INSERT的?例如一个普通的INSERT我想要这样:$sql=$this->db("INSERTINTOsome_table(id,my_value)VALUES(:id,:my_value)");$sql->bindValues([':id'=>$id,':my_value'=>$my_value]);$sql->execute();现在,如果我想创建一个批量INSERT怎么办?如果没有绑定(bind)值,你可以这样:foreach($fooas$bar){$data_sql.='('.$id.','"'".$bar."'),"}$dat

mysql - 如何在 Yii2 中进行批量数据库插入?

我想知道你是如何在Yii2中做一个批量数据库INSERT的?例如一个普通的INSERT我想要这样:$sql=$this->db("INSERTINTOsome_table(id,my_value)VALUES(:id,:my_value)");$sql->bindValues([':id'=>$id,':my_value'=>$my_value]);$sql->execute();现在,如果我想创建一个批量INSERT怎么办?如果没有绑定(bind)值,你可以这样:foreach($fooas$bar){$data_sql.='('.$id.','"'".$bar."'),"}$dat

Yii框架中的PHP异步方法调用

问题我想知道是否可以在Action呈现View时从其中一个Action异步调用YiiController方法,让该方法完成长时间运行的操作。我很想做类似下面代码的事情,我不需要从my_long_running_func返回结果。publicfunctionactionCreate(){$model=newVacancies;if(isset($_POST['Vacancies'])){$model->setAttributes($_POST['Vacancies']);$model->save();//Iwish:)call_user_func_async('my_long_runni

Yii框架中的PHP异步方法调用

问题我想知道是否可以在Action呈现View时从其中一个Action异步调用YiiController方法,让该方法完成长时间运行的操作。我很想做类似下面代码的事情,我不需要从my_long_running_func返回结果。publicfunctionactionCreate(){$model=newVacancies;if(isset($_POST['Vacancies'])){$model->setAttributes($_POST['Vacancies']);$model->save();//Iwish:)call_user_func_async('my_long_runni

YII 2框架的问题

我试图用YII2创建一个博客,我的框架令人困惑地调用数据库的数据。例如,当我从“用户”表中调用“用户名”时,$model,'attributes'=>['user.fullname',--->>Yii2isthinkingthatthisisacategoryandnotausertable'title','description','content:html','count_view','status','created_at',],])?>我遇到了这个错误:->>未知属性:app\models\cattory::fullname请您能帮我解决这个问题,在哪里我犯了一个错误?这是

php - MySQL Union All 在 Yii 的默认范围内

我使用的是Yii1.1.16,想知道Union2模型如何使用默认范围?model1=abcmodel2=abc2基本上我想做一个简单的联合SELECT*FROM`abc`UNIONALLSELECT*FROM`abc2`还没有真正使用默认范围,所以对这个概念有点陌生。两个表的列号和列名完全相同。我试过了,但失败了。在我的abc模型中publicfunctiondefaultScope(){returnarray('alias'=>'t2','select'=>array('t.*,t2.*'),'union'=>array('SELECT*FROM`abc2`'));}更新:刚刚实现h