コード例 #1
0
 /**
  * Finds the Country model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Country the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Country::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #2
0
ファイル: _form.php プロジェクト: alexsynytskiy/Dynamomania
?>

<div class="command-form">

    <?php 
$form = ActiveForm::begin(['options' => ['autocomplete' => 'off', 'enctype' => 'multipart/form-data']]);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => 255]);
?>

    <?php 
$availableCountries = [];
if (!$model->isNewRecord) {
    $country = Country::findOne($model->country_id);
    if (isset($country->id)) {
        $availableCountries = [$country->id => $country->name];
    }
}
echo $form->field($model, 'country_id')->widget(SelectizeDropDownList::classname(), ['loadUrl' => Url::to(['country/country-part-list']), 'items' => $availableCountries, 'options' => ['multiple' => false], 'clientOptions' => ['valueField' => 'value', 'labelField' => 'text', 'persist' => false]]);
?>

    <?php 
$pluginOptions = ['showUpload' => false, 'showRemove' => false, 'overwriteInitial' => true, 'browseLabel' => "Обзор...", 'allowedFileExtensions' => ['jpg', 'gif', 'png']];
$icon = $model->getAsset();
if (!$model->isNewRecord && $icon->getFileUrl()) {
    $pluginOptions['initialPreview'] = [Html::img($icon->getFileUrl())];
}
echo $form->field($model, 'icon')->widget(FileInput::classname(), ['options' => ['accept' => 'image/*', 'multiple' => false], 'pluginOptions' => $pluginOptions]);
?>