$this->registerJs("CKEDITOR.plugins.addExternal('pbckcode', 'plugins/pbckcode/plugin.js', '');", $this::POS_READY, 'tinymcepluginpbckcode');
<?= $form->field($model, 'content')->widget(CKEditor::className(), [
'preset' => 'custom',
'options' => ['rows' => 15],
'clientOptions' => [
'extraPlugins' => 'pbckcode',
'toolbarGroups' => [
['name' => 'undo'],
['name' => 'basicstyles', 'groups' => ['basicstyles', 'cleanup']],
['name' => 'colors'],
['name' => 'links', 'groups' => ['links', 'insert']],
['name' => 'others', 'groups' => ['others', 'about']],
//['name' => 'youtube'], // <--- OUR NEW PLUGIN YAY!
['name' => 'pbckcode']
]
],
]) ?>
<?= $form->field($model, 'status_id')->dropDownList($model->statusList); ?>
public static function getStatusList() {
$droptions = Status::find()->asArray()->all();
return Arrayhelper::map($droptions, '_id', 'name');
}
<?php
/**
* Created by PhpStorm.
* User: Jakeroid
* Date: 17-Jul-15
* Time: 13:28
*/
namespace app\modules\cp\models;
use app\models\Attachment;
use Yii;
use yii\base\Model;
use app\models\Team;
class TeamForm extends Model
{
public $name;
public $logo;
/**
* @var Team
*/
private $dbModel;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
[['name'], 'required'],
[['name'], 'string', 'max' => 255],
[['logo'], 'file', 'extensions' => 'gif, jpg, jpeg, png', 'skipOnEmpty' => false],
];
}
/**
* @return array customized attribute labels
*/
public function attributeLabels()
{
return [
'name' => Yii::t('app', 'Team name'),
'logo' => Yii::t('app', 'Team logo (flag)'),
];
}
/**
* @param $is_update boolean
* @return boolean from save method of dbModel
*/
public function saveModel($is_update = false)
{
$attachment = new Attachment();
$attachment->type = 'team_logo';
$attachment->attachments_group_id = 0;
$attachment->saveWithFile($this->logo);
if ($is_update) {
$this->dbModel->logo->delete();
}
$this->dbModel->logo_id = $attachment->id;
$this->dbModel->name = $this->name;
return $this->dbModel->save();
}
public function loadModel($model)
{
$this->dbModel = $model;
$this->name = $model->name;
}
/**
* @return Team from current dbModel
*/
public function getModel()
{
return $this->dbModel;
}
}
public function actionUpdate($id)
{
$model = new TeamForm();
$model->loadModel($this->findModel($id));
if ($model->load(Yii::$app->request->post())) {
$model->logo = UploadedFile::getInstance($model, 'logo');
if ($model->validate() && $model->logo) {
$model->saveModel(true);
return $this->redirect(['view', 'id' => $model->getModel()->id]);
}
}
return $this->render('update', [
'model' => $model,
]);
}
# если картинка, то мод реврайт кидает на скрипт,
# обрабатывающий изображения
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ximage/[a-zA-Z\_\-0-9\/]+[.]{1}[jpg|jpeg?] ximg.php
Yii::createObject('cache',[
'class' => ...,
....
]);
<?php
define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require_once __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
$container = new \yii\di\Container;
$container->set('cache', [
'class' => 'yii\caching\FileCache',
'cachePath' => $_SERVER['DOCUMENT_ROOT'] . '/cache/',
'cacheFileSuffix' => '.xxx',
]);
$cache = $container->get('cache');
$container->set('connection', [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2-app',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'queryCache' => $cache
]);
$connection = $container->get('connection');
$connection->open();
$q = "SELECT * FROM user_user";
$a = $connection->createCommand($q)->cache(45)->queryAll();