newsNew1.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. use yii\helpers\Html;
  3. use yii\widgets\ActiveForm;
  4. //use mihaildev\ckeditor\CKEditor;
  5. use kartik\datetime\DateTimePicker;
  6. use dosamigos\ckeditor\CKEditor;
  7. //use dosamigos\ckeditor\CKEditorInline;
  8. use iutbay\yii2kcfinder\KCFinderInputWidget;
  9. use iutbay\yii2kcfinder\KCFinder;
  10. $request = Yii::$app->request;
  11. $id = $request->get('id');
  12. if( $id ){
  13. $this->title="Редактирование статьи";
  14. $news = \app\models\News::find()->andWhere(['id'=>$id])->one();
  15. // print_a( $news );
  16. }else{
  17. $this->title="Новая статья";
  18. $anews = [
  19. 'title' => ''
  20. ];
  21. $news = new \app\models\News();;
  22. $news->title = '';
  23. }
  24. $form = ActiveForm::begin([
  25. 'id' => 'login-form',
  26. 'options' => ['class' => 'form-horizontal'],]);
  27. echo $form->field($news, 'dt_pub')->widget(
  28. DateTimePicker::class,
  29. [
  30. 'options' => ['placeholder' => 'Время публикации'],
  31. 'convertFormat' => true,
  32. 'pluginOptions' => [
  33. 'format' => 'dd-MM-yyyy HH:i',
  34. 'type' => DateTimePicker::TYPE_COMPONENT_PREPEND,
  35. 'startDate' => '01-Mar-2014 12:00',
  36. 'todayHighlight' => true,
  37. 'language' => 'ru_RU',
  38. 'autoclose' => true,
  39. ]
  40. ]
  41. )->label('Дата публикации');
  42. echo $form->field($news, 'title')->textInput([
  43. 'maxlength' => true,
  44. 'class' => 'form-control js-word-count-input',
  45. 'placeholder' => 'Заголовок новости'
  46. ])->label('Заголовок');
  47. ?>
  48. <div class="news__input-word-count"><span class="count">0</span> из 80</div>
  49. <?
  50. echo $form->field($news, 'lid')->textarea([
  51. 'maxlength' => true,
  52. 'class' => 'form-control js-word-count-input',
  53. 'placeholder' => 'Лид'
  54. ])->label('Новость кратко');
  55. /*
  56. echo $form->field($news, 'text')->textarea([
  57. 'maxlength' => true,
  58. 'class' => 'form-control js-word-count-input',
  59. ])->widget(CKEditor::className(),[
  60. 'editorOptions' => [
  61. 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать
  62. 'inline' => false, //по умолчанию false
  63. ],
  64. ]);
  65. */
  66. /*
  67. echo $form->field($news, 'text')->widget(CKEditor::className(), [
  68. 'options' => ['rows' => 6],
  69. 'preset' => 'basic'
  70. ]);
  71. */
  72. $kcfOptions = array_merge(KCFinder::$kcfDefaultOptions, [
  73. 'uploadURL' => Yii::getAlias('@web').'/images/design/',
  74. 'uploadDir' => '@webroot/images/design/',
  75. 'disabled'=> false,
  76. 'access' => [
  77. 'files' => [
  78. 'upload' => true,
  79. 'delete' => true,
  80. 'copy' => true,
  81. 'move' => true,
  82. 'rename' => true,
  83. ],
  84. 'dirs' => [
  85. 'create' => true,
  86. 'delete' => true,
  87. 'rename' => true,
  88. ],
  89. ],
  90. 'types' => array(
  91. // (F)CKEditor types
  92. 'files' => "pdf doc xsl mp3 wav ogv docx m4a wma ogg oga wav",
  93. 'flash' => "swf",
  94. 'images' => "*img",
  95. 'audio' => "mp3 wav ogv m4a wma ogg oga",
  96. // TinyMCE types
  97. 'file' => "",
  98. 'media' => "swf flv avi mpg mpeg qt mov wmv asf rm",
  99. 'image' => "*img",
  100. ),
  101. ]);
  102. Yii::$app->session->set('KCFINDER', $kcfOptions);
  103. echo $form->field($news, 'text')->widget(CKEditor::className(), [
  104. 'kcfinder' => true,]);
  105. echo Html::submitButton('Send', ['class' => 'btn btn-success']);
  106. ActiveForm::end();