对于我们的每个二进制资产,我们生成MD5哈希.这用于检查某个二进制资产是否已存在于我们的应用程序中.但两个不同的二进制资产是否可能生成相同的MD5哈希值.那么两个不同的字符串是否可能生成相同的MD5哈希?
如何使一个dropdown
在yii2
使用activeform
和模式?由于所有方法都已改变yii2
,如何在新的方法中完成?
在我的视图中添加javascript会导致ReferenceError: $ is not defined
.我认为问题是由于Yii2在我的页面上最后注入脚本.如何解决这个问题?
或者我如何阻止Yii2自动加载脚本文件?
我的看法
<?php
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\helpers\UrlManager;
use yii\widgets\ActiveForm;
use backend\controllers\StandardController;
use backend\models\standard;
?>
<div class="domain-form">
<?php $form = ActiveForm::begin(); ?>
<?php
<?= $form->field($model, 'clause')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'name')->textarea(['rows' => 6]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<script type="text/javascript">
$("document").ready( function () {
alert("hi");
});</script>
Run Code Online (Sandbox Code Playgroud)
我需要让这个简单的脚本在页面加载后显示警告.我没有在这里调用任何脚本文件,因为yii通过调用自动加载(我认为)在布局中
AppAsset::register($this);
Run Code Online (Sandbox Code Playgroud)
这导致脚本文件在我的自定义脚本之后在页面末尾注册.
怎么解决这个?
如何在Yii2中删除特定网格视图的摘要和排序器.在Yii1.1中,我们可以通过设置模板属性来实现.在yii2中如何实现这一目标?
如何在yii2中将图像放入GridView?我有以下代码.但它没有显示图像,因为它没有给出任何图像网址.在哪里放图像网址?
<?php echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'c_id',
'name:ntext',
'description:ntext',
array(
'format' => 'image',
'attribute'=>'logo',
),
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Run Code Online (Sandbox Code Playgroud) 尝试通过put显示登录用户的用户名
{{ app.user.username }}
Run Code Online (Sandbox Code Playgroud)
在base.html.twig给我一个错误
Impossible to access an attribute ("username") on a NULL variable ("") in ::base.html.twig at line 45
Run Code Online (Sandbox Code Playgroud)
接受它就像
{{ app.security.getToken().getUser().getUsername() }}
Run Code Online (Sandbox Code Playgroud)
导致以下错误.
Impossible to invoke a method ("getUser") on a NULL variable ("")
Run Code Online (Sandbox Code Playgroud)
如何在symfony中全局访问登录用户的属性?如何修复错误?
在Yii2中,我希望我的输入字段之一在用户开始输入时自动完成.Below是我使用的代码Jui Autocomplete
.
<?php
$items= ArrayHelper::map(Company::find()->all(), 'c_id', 'name');
echo AutoComplete::widget([
'model' => $model,
'attribute' => 'company',
'clientOptions' => [
'source' => $items,
],
]);?>
Run Code Online (Sandbox Code Playgroud)
这不起作用.当我打印我的阵列时,我喜欢
Array ( [1] => abc [2] => xyz [4] => pqr )
Run Code Online (Sandbox Code Playgroud)
当我手动设置时,我得到它的工作
$items=['abc','xyz','pqr'];
Run Code Online (Sandbox Code Playgroud)
原因可能是我c_id's
没有订购?但我想获得c_id
提交的价值!任何想法如何解决这个问题?
我有条款为我的申请中的公司上传徽标.上传和保存创建配置文件工作正常.但是在更新时,如果我不再上传它,徽标就会变空!
这是我的更新表格
<?php $form = ActiveForm::begin([
'options' => ['enctype'=>'multipart/form-data']
]); ?>
.....
<?= $form->field($model, 'logo')->fileInput() ?>
...
Run Code Online (Sandbox Code Playgroud)
我的控制器动作
if ($model->load($_POST) ) {
$file = \yii\web\UploadedFile::getInstance($model, 'logo');
if($file){
$model->logo=$file; }
if($model->save()){
if($file)
$file->saveAs(\Yii::$app->basePath . '/web/images/'.$file);
}
return $this->redirect(['profile']);
} else {
return $this->renderPartial('update', [
'model' => $model,
]);
}
Run Code Online (Sandbox Code Playgroud)
我的规则:
public function rules()
{
return [
[['logo'], 'image', 'extensions' => 'jpg,png', 'skipOnEmpty' => true],
[['name'], 'required'],
[['name', 'description'], 'string'],
];
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗????
我的模型中有一个afterSave函数,它根据用户给出的开始时间和持续时间保存某些服务的到期日期.我的afterSave
工作正常,但在保存模型而不是显示空白页面后,它没有被重定向.
模型:
public function afterSave($insert)
{
$month= "+".$this->duration_in_months." month";
$this->exp_date=date("Y-m-d H:i:s",strtotime($month));
$this->save(['exp_date']);
return parent::afterSave($insert);
}
Run Code Online (Sandbox Code Playgroud)
控制器:
if($model->save())
return $this->redirect(['view', 'id' => $model->sub_id]);
}
Run Code Online (Sandbox Code Playgroud)
我如何重定向afterSave?提前感谢!
我正在尝试通过简单地执行文档中给出的命令来使logstash安装工作,以回显曾经输入的内容.但是这给了我以下错误.
我的命令
C:\logstash-1.4.0\bin>logstash.bat agent -e 'input{stdin{}}output{stdout{}}'
Run Code Online (Sandbox Code Playgroud)
而错误
Error: Expected one of #, input, filter, output at line 1, column 1 (byte 1) aft
er
You may be interested in the '--configtest' flag which you can
use to validate logstash's configuration before you choose
to restart a running system."
Run Code Online (Sandbox Code Playgroud)
请帮忙.谢谢!