Yii2如何在Html activeInput上分配小部件(Yii2 how to assign widget on Html activeInput)
如何将Select2小部件分配给activeInput输入。 我的代码如下所示:
= Html::activeInput('text', $company, 'country_id')->widget(Select2::classname(), [ some options ]) ?>
这引发错误的课程是: PHP Fatal Error 'yii\base\ErrorException' with message 'Call to a member function widget() on string' 。 解释不好,但认为这个问题很简单,那些知道答案的人:)提前谢谢!
How to assign the Select2 widget to an activeInput input. My code look like so:
= Html::activeInput('text', $company, 'country_id')->widget(Select2::classname(), [ some options ]) ?>
This throws error ofcourse which is : PHP Fatal Error 'yii\base\ErrorException' with message 'Call to a member function widget() on string'. The explanation is poor but think the question is simple for those who know the answer :) Thank you in advance!
原文:https://stackoverflow.com/questions/50714315
更新时间:2019-09-13 08:16
最满意答案
你不能,因为它没有多大意义 - activeInput()只产生输入,这应该由widget在你的情况下产生,所以activeInput()是完全不必要的。 直接运行小部件:
= Selet2::widget([
'model' => $model,
'attribute' => 'country_id',
])
You can't, because it does not make much sense - activeInput() generates only input, which should be generated by widget in your case, so activeInput() is completely unnecessary. Just run widget directly:
= Selet2::widget([
'model' => $model,
'attribute' => 'country_id',
])
相关问答
最后我找到了解决办法。 它取决于Yii2扩展和AssetBundles 。 这个故事很简单,只需将一个文件夹中的所有文件放置在默认的Yii2文件夹中,例如:common,vendor.- 顺便提一下,供应商可以在基本和高级yii2应用程序的模板中找到 - 。 除了所有的文件,即我的情况下 ,小部件类php文件和JavaScript文件,你必须创建YourWidgetNameAsset php类文件。 事实上,解决方案的主要关键在于该类。 我的情况 我有一个名为JuiThemeSelectWidge
...
请看看demos @ http://demos.krajee.com/widget-details/select2 您可以使用Select2而不使用ActiveForm,甚至不使用Model。 从演示示例中,下面是相关的代码片段: use kartik\widgets\Select2
// With a model and without ActiveForm
echo Select2::widget([
'model' => $model,
'attribute' => 'st
...
可能有几个原因。 最明显的一个(这是你的情况)是如果你使用renderPartial()而不是renderAjax()会发生这种情况。 他们都做同样的事情,但有一点不同: renderPartial()不加载资源(css,js)。 但是renderAjax()会加载资源。 它是为部分通过ajax加载页面的用例而设计的。 可能发生的第二点是资产通过Pjax加载一些较旧版本的bower\yii2-pjax (<= 2.0.5)。 你可以在这里找到答案。 对于2.0.6+,您不应该遇到问题。 There
...
你不会只使用: =Yii::t('common', 'Participate'); ?>
Wouldn't you just use: =Yii::t('common', 'Participate'); ?>
...
strstr() searcjhes字符串中的字符串http://php.net/manual/en/function.strstr.php 所以你可以尝试: if (strstr($post->body, '
获取标记的另一种方法可能是一些正则表达式,虽然它可能不匹配取决于HTML: <?php
$html = '
![blah.jpg](blah.jpg)
...
你不能,因为它没有多大意义 - activeInput()只产生输入,这应该由widget在你的情况下产生,所以activeInput()是完全不必要的。 直接运行小部件: = Selet2::widget([
'model' => $model,
'attribute' => 'country_id',
])
You can't, because it does not make much sense - activeInput() generates only input
...
您不必使用Yii2 Autocomplete的model参数,而必须使用其source参数,并将其指向一个端点和控制器,该端点和控制器将查询两个表,并在每次由Autocomplete调用结果时返回结果。 Instead of using Yii2 Autocomplete's model parameter, you have to use its source parameter, and point it to an endpoint and controller that queries b
...
您必须在widget的run()函数中添加return语句: return $this->render('sideb',[
'model' => $models
]);
You must add return statement in run() function of widget: return $this->render('sideb',[
'model' => $models
]);
你应该使用format => raw = GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'id',
[
'attribute'=> 'template_name',
'label'=>'Test Name',
'format' => 'raw',
'value'
...
如果你看一下yii\widgets\Breadcrumbs你会发现breadcrumbs项目中有第三个参数 来自Yii2文件 [
'label' => 'Post Category',
'url' => ['post-category/view', 'id' => 10],
'template' => "
{link}\n", // template for this link only],
所以在你的主布局文
...