- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在这一点上撕裂我的头发,希望有人能帮助我!
我在 Yii2 中使用 Kartik-V Typeahead Advanced 小部件。
该插件有效,因为该功能在页面上完美运行,我搜索并且结果显示在自动完成列表中。
不幸的是,我无法将结果存储到我的数据库中。我在以下行看到一个问题:
->where([ 'name' => $model->name ])//This variable is returning null
我是否试图错误地存储数据?我已经尝试了所有我能想到的方法,但我相信这里有人会想出更好的办法!
完整代码见下文。
我的 Controller :
public function actionIndex()
{
$model = new Member();
if ($model->load(Yii::$app->request->post())) {
$test = Test::find()
->where([ 'name' => $model->name ])//This variable is returning null
->one();
$test->updateCounters(['times_used' => 1]);
}
return $this->render('index', [
'model' => $model,
]);
}
/*************
* Initial prefetch of results
*************/
public function actionPrefetchlist() {
$query = new Query;
$query->select('name')
->from('test_table')
->limit(10)
->orderBy('times_used');
$command = $query->createCommand();
$data = $command->queryAll();
$out = [];
foreach ($data as $d) {
$out[] = ['value' => $d['name']];
}
echo Json::encode($out);
}
/*************
* Remote results
*************/
public function actionRemotelist() {
$query = new Query;
$query->select('name')
->from('test_table')
->where('name LIKE "%' . $q .'%"')
->limit(10)
->orderBy('times_used');
$command = $query->createCommand();
$data = $command->queryAll();
$out = [];
foreach ($data as $d) {
$out[] = ['value' => $d['name']];
}
echo Json::encode($out);
}
查看文件:
echo $form->field($model, 'name')->label(false)->widget(Typeahead::classname(), [
'name' => 'name',
'options' => ['placeholder' => 'Filter as you type ...'],
'pluginOptions' => ['highlight'=>true],
'dataset' => [
[
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')",
'display' => 'value',
'prefetch' => Url::to(['prefetchlist']),
'remote' => [
'url' => Url::to(['remotelist']) . '?q=%QUERY',
'wildcard' => '%QUERY'
]
]
]
]);
最佳答案
你在这里问一个新模型:
$model = new Member();
所以你得到一个空模型所以 $model->name
是空的如果你设置模型 $model->name='test';
比它会填充所以,先填充模型
关于mysql - Yii2 Kartik-V Typeahead 高级小部件 : How to store result in Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33669835/
如何在 Kartik Gridview 中禁用分页?我正在使用如下代码 echo GridView::widget([ 'dataProvider'=>$dataProvide
如何禁用kartik gridview中的pdf导出属性? 我已经安装了 kartik gridview,它给了我以下错误。 The class '\kartik\mpdf\Pdf' was not
我的 Select2 控件位于引导类“col-sm-3”的列内。它还附加到表单字段。但宽度不想成为父列的 100%。如果我使浏览器窗口变小(列自动重新排列后),Select2 将遵循父列的宽度。此外,
我在 yii2 项目中使用 kartik 文件输入小部件。 http://demos.krajee.com/widget-details/fileinput 一切都很好,直到访问更新页面,其中使用“i
这是我的 composer .json 文件 { "minimum-stability": "stable", "require": { "php": ">=5.4.0", "yiis
您好,我正在尝试使文件上传正常工作,但我不知道如何触发上传按钮。 我正在使用:https://github.com/kartik-v/yii2-widget-fileinput 我的代码:
好的,我正在尝试使用 Kartik Depdrop 小部件,但出现此错误 500(内部服务器错误) 我有父模型 Brand 和子模型 CarModel 这是我的文件: CarsController.p
我在我的 Yii2 网页上使用了 Kartik GridView(左)。我想保持表格格式,如下所示(右) 查看.php $dataProviderSanChu, 'filterModel'
我在我的 yii2 网格中添加了一个复选框列,并创建了一个可以删除所有选定值的按钮。但是,在我的操作中,我已经使删除图标仅显示依赖项成为可能,如下所示。 'delete' => 函数($model,
我创建了一个 yii2 kartik select2 小部件来选择多个车型,如下所示 'drp-make', 'data' => Car::getCarMakesEnglish(),
当我拉入 kartik 可扩展行网格时,使用 pjax 未应用可编辑列样式。我该怎么做才能将 css 应用于此列? $dataProvider, 'filterModel' => $
在 kartik DatePicker Yii2 中有没有办法 - 我可以禁用大于当前日期的日期? 例如:如果今天是 2016 年 3 月 14 日,则应禁用 2016 年 3 月 15 日的日历日期
如何将预输入结果放置在文本输入上方?对我来说最好的办法是向这个小部件添加一个选项或者一些 css 规则? 最佳答案 此刻,我终于在 typeahead 小部件的 render 事件中使用了 jQuer
我包含 Kartik yii2 ExportMenu 插件,它对于所有数据导出都工作良好,但现在我只想导出在网格上检查的选定行。 'yii\grid\SerialColumn'], 'u
这是默认代码 GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel,
有没有人能够为 Yii GridView DataColumn 设置自动换行? 这是我设置列的方式: [ 'class' => 'kartik\grid\DataColumn', '
我想要一个启用多日期的内联日期选择器。 它呈现正确但仅返回最后选择的日期。 返回值:'12.11.2016' 如果我将 'type' 设置为 TYPE_INPUT 一切正常。 预期返回值:'23.11
当我尝试使用 kartik select2 时,下拉列表不出现模态插件。当我在没有模态的情况下使用它时,它就像魅力一样。这与从插件网站获取的代码相同,但它仍然不起作用。我在浏览器生成的源代码中发现se
我尝试从问题 DatePicker Week number column to be clickable on selecting week 的示例答案中移动此代码在 Yii2 上使用 kartik
我使用 Select2 小部件将选定的标签输入存储到 MySQL 数据库中。我希望像 010102, 010103, 010299 这样的东西存储在数据库表中。 这是view.php echo
我是一名优秀的程序员,十分优秀!