本文整理汇总了PHP中yii\db\ActiveRecord::getFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::getFiles方法的具体用法?PHP ActiveRecord::getFiles怎么用?PHP ActiveRecord::getFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\db\ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::getFiles方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$confirm = Yii::t('yii', 'Are you sure you want to delete this item?');
$js = <<<JS
\$(".delete-button").click(function(){
var tr = this.closest('tr');
var url = \$(this).data('url');
if (confirm("{$confirm}")) {
\$.ajax({
method: "POST",
url: url,
success: function(data) {
if (data) {
tr.remove();
}
}
});
}
});
JS;
Yii::$app->view->registerJs($js);
return GridView::widget(['dataProvider' => new ArrayDataProvider(['allModels' => $this->model->getFiles()]), 'layout' => '{items}', 'tableOptions' => $this->tableOptions, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => $this->getModule()->t('attachments', 'File name'), 'format' => 'raw', 'value' => function ($model) {
return Html::a("{$model->name}.{$model->type}", $model->getUrl());
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', '#', ['class' => 'delete-button', 'title' => Yii::t('yii', 'Delete'), 'data-url' => Url::to(['/attachments/file/delete', 'id' => $model->id])]);
}]]]]);
}
示例2: run
public function run()
{
if (!$this->model) {
return Html::tag('div', Html::tag('b', Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The model cannot be empty.'), ['class' => 'alert alert-danger']);
}
$hasFileBehavior = false;
foreach ($this->model->getBehaviors() as $behavior) {
if (is_a($behavior, FileBehavior::className())) {
$hasFileBehavior = true;
}
}
if (!$hasFileBehavior) {
return Html::tag('div', Html::tag('b', Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The behavior FileBehavior has not been attached to the model.'), ['class' => 'alert alert-danger']);
}
Url::remember(Url::current());
return GridView::widget(['dataProvider' => new ArrayDataProvider(['allModels' => $this->model->getFiles()]), 'layout' => '{items}', 'tableOptions' => $this->tableOptions, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => $this->getModule()->t('attachments', 'File name'), 'format' => 'raw', 'value' => function ($model) {
return Html::a("{$model->name}.{$model->type}", $model->getUrl());
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['/attachments/file/delete', 'id' => $model->id], ['title' => Yii::t('yii', 'Delete'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'data-method' => 'post']);
}]]]]);
}
示例3: run
public function run()
{
if (!$this->model) {
return Html::tag('div', Html::tag('b', Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The model cannot be empty.'), ['class' => 'alert alert-danger']);
}
$hasFileBehavior = false;
foreach ($this->model->getBehaviors() as $behavior) {
if ($behavior instanceof FileBehavior) {
$hasFileBehavior = true;
break;
}
}
if (!$hasFileBehavior) {
return Html::tag('div', Html::tag('b', Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The behavior FileBehavior has not been attached to the model.'), ['class' => 'alert alert-danger']);
}
$confirm = Yii::t('yii', 'Are you sure you want to delete this item?');
$js = <<<JS
\$(".delete-button").click(function(){
var tr = this.closest('tr');
var url = \$(this).data('url');
if (confirm("{$confirm}")) {
\$.ajax({
method: "POST",
url: url,
success: function(data) {
if (data) {
tr.remove();
}
}
});
}
});
JS;
Yii::$app->view->registerJs($js);
return GridView::widget(['dataProvider' => new ArrayDataProvider(['allModels' => $this->model->getFiles()]), 'layout' => '{items}', 'tableOptions' => $this->tableOptions, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => $this->getModule()->t('attachments', 'File name'), 'format' => 'raw', 'value' => function ($model) {
return Html::a("{$model->name}.{$model->type}", $model->getUrl(), ['class' => ' group' . $model->itemId, 'onclick' => 'return false;']);
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-trash"></span>', '#', ['class' => 'delete-button', 'title' => Yii::t('yii', 'Delete'), 'data-url' => Url::to(['/attachments/file/delete', 'id' => $model->id])]);
}]]]]) . Colorbox::widget(['targets' => ['.group' . $this->model->id => ['rel' => '.group' . $this->model->id, 'photo' => true, 'scalePhotos' => true, 'width' => '100%', 'height' => '100%', 'maxWidth' => 800, 'maxHeight' => 600]], 'coreStyle' => 4]);
}