嗨,大家好我正在使用以下代码,并limit没有工作,但如果我看到的命令比它显示limit在那,但当我将查询传递给ActiveDataProvider它获取所有记录
$data= User::find()->where(['category_id'=> 5])->orderBy(['rand()' => SORT_DESC])->limit(4);
$command = $data->createCommand();
$data2 = $command->queryAll();// This works fine and fetch only 4 data
$dataProvider = new ActiveDataProvider([
'query' => $data,
]); // But this displays all data without limit
Run Code Online (Sandbox Code Playgroud)
我在这做什么错了???
嗨,伙计们我正在使用bootstrapcarousal并且图像高度和宽度有问题.即使我在img属性中定义它仍然显示为原始分辨率,以下是我正在使用的代码
<div class="col-md-6 col-sm-6">
<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">
<div class="item active">
<img src="http://placehold.it/650x450/aaa&text=Item 3" height="300" width="300" />
</div>
<div class="item">
<img src="http://placehold.it/350x350/aaa&text=Item 3" height="300" width="300" />
</div>
<div class="item">
<img src="http://placehold.it/350x350/aaa&text=Item 3" height="300" width="300" />
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="icon-prev"></span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="icon-next"></span>
</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是演示.
无论原始分辨率如何,我该怎么做才能以一定的高度和宽度填充图像.
嗨伙计们,我很困惑一件事
我想写下面的查询,yii2但我无法得到预期的输出
SELECT * FROM user where category_id=5 ORDER BY rand() LIMIT 4
Run Code Online (Sandbox Code Playgroud)
为此,我做了以下
$data= User::find()->where(['category_id'=> 5])->orderBy(['rand()'])->limit(4);
Run Code Online (Sandbox Code Playgroud)
但它会生成如下命令
SELECT * FROM `user` WHERE `category_id`=5 ORDER BY `0` LIMIT 4
Run Code Online (Sandbox Code Playgroud)
哪个不是有效的mysql语句,那么我该如何才能使查询正确?
我的目标是从user表中获取任意随机的4条记录.
我在Yii1.x有一个项目,现在我正在使用Yii2进行相同的项目
项目层次结构就是这样的
Project1(yii1)/all yii files + project2(yii2)
project2(yii2)/frontend + /common + /backend
Run Code Online (Sandbox Code Playgroud)
现在我想知道,如果是可以用project2/common/models在project1/protected/controllers
我怎样才能完成这项任务?
谢谢
我想知道yii2 gridview复选框列中是否有任何内置选项,一次选择/取消选择所有行.
例如,如果我在gridview中有500条记录,并且我一次显示100条记录,那么我一次只能选择100条记录并执行任何批量操作.
我希望用户能够一次选择所有500条记录,并立即对这些记录执行任何批量操作.希望大家都能得到我的问题
我提出了一个建议,以警予在框架的业主github,他们已经证实,他们会做这种增强很快就好了,放在增强部分这一问题,所以希望他们将包括它很快,但在那之前引导我任何替代方式来实现这一目标
谢谢
在同一个表单上有多个模型我不想在两个模型上保存数据,但我只想在视图文件上显示一个变量
我有2个表
Organiser和Event
Organiser将登录和Create Event
现在有几个字段这是常见的用户点击登录,所以当两个表中的Create Event按钮,我想显示address从Organiser表的形式
这是我到目前为止所做的,这可能不是正确的方法,所以让我知道是否可以通过任何其他更简单的方式实现
public function actionCreate()
{
$model = new Event();
$model2 = $this->findModel2(Yii::$app->user->id);
if ($model->load(Yii::$app->request->post())) {
if($_POST['User']['address'] == null)
{
$model->location = $model2->address;
}
else{
$model->location = $_POST['User']['address'];
}
$model->is_active = 1 ;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
'model2' => $model2
]);
}
}
protected function findModel2($id)
{
if (($model2 = User::findOne($id)) !== null) …Run Code Online (Sandbox Code Playgroud) 我正在尝试访问视图文件上的变量,Gridview但它抛出了it should be array but null given我在$totalDays视图文件顶部声明的错误,我正在使用它,Gridview如下所示
[
'attribute' => 'class_id',
'format' => 'raw',
'label' => "Class Date",
'value' => function ($model) {
array_push($totalDays,$model->class->date);
return $model->class->date;
},
'footer'=> '<span>Total Days</span>',
],
Run Code Online (Sandbox Code Playgroud)
但它抛出以下错误
array_push() 期望参数 1 是数组,给定 null
我正在 VueJs 中构建一个组件,如果条件为真,则需要打开模态并从控制器获取数据并在模态中显示。
\n\n我在网上查找过,但找不到如何在使用 接收数据后设置动态内容axios。
这是我的 ModalComponent.vue
\n\n<template>\n<div class="modal fade show" id="myModal" style="display: block;">\n <div class="modal-dialog" role="document">\n <div class="modal-content">\n <div class="modal-header">\n <h4 class="modal-title"><slot name="modal-header"></slot></h4>\n <button type="button" class="close" @click="$emit(\'close\')" data-dismiss="modal" aria-label="Close">\n <span aria-hidden="true" >\xc3\x97</span>\n </button>\n </div>\n <div class="modal-body">\n <slot name="modal-text"></slot>\n </div>\n <div class="modal-footer">\n <slot name="modal-footer"></slot>\n <button type="button" class="btn btn-danger" @click="$emit(\'close\')" data-dismiss="modal">Close</button>\n </div>\n </div>\n </div>\n</div>\n</template>\n\n<script>\n export default {\n name: "ModalComponent"\n }\n</script>\nRun Code Online (Sandbox Code Playgroud)\n\n在其他组件 ExampleComponent 中,我可以使用这样的按钮显示模式
\n\n<button @click="showModal = true">Show Modal</button>\n<modal-component v-if="showModal" @close="showModal = false">\n <template slot="modal-header"> …Run Code Online (Sandbox Code Playgroud) 我遇到了一个奇怪的问题,不知道如何解决它。我正在使用移动应用程序中的 Web 服务来验证登录详细信息,并为该应用程序发送数据$_POST到我的 api,然后 api 返回数据。
现在,相同的代码似乎可以在我的手机上正常工作,但如果我在邮递员中测试它,它就不起作用,并且我file_get_contents ( "php://input" )不会返回任何数据。
localhost这是在我和服务器上不起作用的代码块,但相同的代码在我的应用程序上运行良好。如果我通过应用程序请求,它会验证数据并让用户登录。
public function getPostdata() {
$post = file_get_contents ( "php://input" );
$data = CJSON::decode ( $post, true );
return $data;
}
Run Code Online (Sandbox Code Playgroud) 我试图从刀片模板中传递 2 个参数,但eventId始终undefined在Vue模板中。
这是我的控制器代码
public function index(Request $request, $eventId)
{
return view('backend.organiser.classes.index')
->withClasses(Classes::orderBy('order')->get())
->withEventId($eventId);
}
Run Code Online (Sandbox Code Playgroud)
以下是我的index.blade.php代码
<div class="row mb-4">
<div class="col">
<div>{{ $eventId }}</div>
<example-component :classes="{{ $classes }}" :eventId="{{ $eventId }}"></example-component>
</div><!--col-->
</div><!--row-->
Run Code Online (Sandbox Code Playgroud)
以下是我的ExampleComponent.vue代码
<script>
export default {
props:['classes','eventId'],
mounted() {
console.log(this.eventId)
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我得到了数据,classes但eventId总是undefined
我在这里做错了什么??
我BearerAuth在我的 yii2 项目中使用,身份验证在我的本地计算机上工作正常,但是当我在我的服务器上上传相同的代码和数据库时,它不工作并抛出Unauthorised错误。
我试图header在屏幕上打印,我可以看到access_token标题中没有。我正在POSTMAN用于测试,我正在使用以下令牌在标头中传递令牌
有什么我做错了吗?有没有其他方法可以Authrorisation在服务器上发送标头?
那access_token是在数据库中。我也尝试在服务器上调试它,但它没有转到User模型的方法findIdentityByAccessToken并在此之前抛出错误。
我无法app.css在我的应用程序中使用 。每次服务器返回以下错误
获取 http://localhost:8000/css/app.css net::ERR_ABORTED 404(未找到)。
我使用刀片页面。
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)
我尝试使用php artisan serve和php -S localhost:8000 -t public并且展位不起作用。