关于Yii2.0 日历插件DatePicker 的问题 [ 2.0 版本 ]
在 _form.php 文件里面已经引用了DatePicker,
use dosamigos\datepicker\DatePicker;
下图左侧是DatePicker路径,右侧是 _form.php页面
为什么还是提示 Class 'dosamigos\datepicker\DatePicker' not found ???
是某个地方需要配置还是怎么回事? DatePicker的命名空间是 namespace dosamigos\datepicker;
已经解决了,原因是少提交了文件
共 4 个回答
-
yesuloveniu 回答于 2016-11-29 10:55 举报
我不是用的composer安装,他报错Class 'app\models\Date' not found ,这个也不是特别详细,麻烦谁有比较详细的介绍,而且不用composer的
共 1 条回复<?php
namespace backend\assets;
use yii\base\Exception;
use yii\web\AssetBundle as BaseAdminLteAsset;/**
- AdminLte AssetBundle
@since 0.1
*/
class DatepickerAsset extends BaseAdminLteAsset
{
public $sourcePath = '@vendor/almasaeed2010/adminlte/plugins';
public $css = ['datepicker/datepicker3.css',
];
public $js = ['datepicker/bootstrap-datepicker.js'
];
public $depends = ['dmstr\web\AdminLteAsset',
];
/**
- @var string|bool Choose skin color, eg.
'skin-blue'
or setfalse
to disable skin loading - @see https://almsaeedstudio.com/themes/AdminLTE/documentation/index.html#layout
*/
public $language = 'zh_CN';
/**
@inheritdoc
/
public function init()
{
// Append skin color file if specified
/if ($this->skin) {if (('_all-skins' !== $this->skin) && (strpos($this->skin, 'skin-') !== 0)) { throw new Exception('Invalid skin specified'); } //$this->css[] = sprintf('css/skins/%s.min.css', $this->skin); $this->css[] = sprintf('css/skins/%s.min.css', $this->skin);
}*/
$this->js[] = 'datepicker/locales/bootstrap-datepicker.zh-CN.js';
parent::init();
}
}
asset/DatepickerAsset.php
- @var string|bool Choose skin color, eg.
view.php
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use dosamigos\datepicker\DatePicker;common\assets\CkeditorAsset::register($this);
<?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'keywords')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'typeId')->dropDownList(\yii\helpers\ArrayHelper::map($configModel['NewsType'],'id','name')); ?> <?= $form->field($model, 'seen')->textInput(['value' => '0']) ?> <?= $form->field($model, 'createTime')->textInput(['id' => 'datepicker'])?> <?= $form->field($model, 'isHot')->textInput(['value' => '0']) ?> <?= $form->field($model, 'isTop')->textInput(['value' => '0']) ?> <?= $form->field($model, 'sort')->textInput(['value' => '0']) ?> <?= $form->field($model, 'status')->textInput(['value' => '0']) ?> <?= $form->field($model, 'content')->textarea(['id' => 'editor1']) ?> <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> <?php ActiveForm::end(); ?>
$this->registerJsFile('/js/news.js',['depends'=>'common\assets\DatePickerAsset']);
$this->registerJsFile('/js/news-editor.js',['depends'=>'common\assets\DatePickerAsset']);
/ @var $this yii\web\View /
/ @var $model backend\models\News /
/ @var $form yii\widgets\ActiveForm /
?>web/asset/js
$('#datepicker').datepicker({format:'yyyy-m-dd', maxDate: "+0d" ,
autoclose: true,
});
blsa点cn 深圳
最后登录:2024-05-15
在线时长:9小时55分
- 粉丝14
- 金钱995
- 威望20
- 积分1285