GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'name',
'filterInputOptions' => [
'placeholder' => 'название книги',
'class' => 'form-control',
'id' => null,
]
]
]
]);
$db = Post::getDb();
$db->transaction(function($db) {
$db->createCommand($sql1)->execute();
$db->createCommand($sql2)->execute();
// ... executing other SQL statements ...
});
$dataProvider = new ActiveDataProvider([
'query' => Images::find()
->orderBy(['sort_order' => SORT_ASC]),
'pagination' => false,
'sort' => false,
]);
use himiklab\sortablegrid\SortableGridView as GridView;
echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
/* твои колонки */
],
]);
$users = User::find()
->indexBy('id')
->all();
$friends = Friend::find()
->indexBy('id')
->all();
$result = array_intersect_key($users, $friends);
namespace frontend\assets;
class AppAsset extends AssetBundle
{
public $sourcePath = '@frontend/resource';
public $css = [
'css/site.css',
];
public $depends = [
'yii\web\JqueryAsset',
];
}
namespace frontend\widgets\FlexSlider;
class SliderAsset extends AssetBundle
{
public $sourcePath = '@vendor/bower/flexslider';
public $css = [
// 'flexslider.css'
];
public $js = [
'jquery.flexslider.js'
];
public $depends = [
'frontend\assets\AppAsset',
'yii\web\JqueryAsset',
];
}
return [
'timeZone' => 'Europe/Minsk',
'components' => [
'formatter' => [
'dateFormat' => 'd.MM.yyyy',
'timeFormat' => 'H:mm:ss',
'datetimeFormat' => 'd.MM.yyyy H:mm',
],
],
];
Yii::$app->getFormatter()->asDate(time());
Yii::$app->getFormatter()->asDatetime(time())
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'created_at:datetime',
],
]); ?>
class DefaultController extends Controller
{
public function actionIndex()
{
/** ваш код */
$this->renderAjax('index', [
/** params */
])
}
}
http://site.com - frontend
http://admin.site.com - backend
class Menu extends ActiveRecord
{
// ...
public static function getList()
{
$data = static::find()
->select(['id', 'parent_id', 'title'])
->orderBy('parent_id ASC')
->asArray()
->all();
$sort = new SortList([
'data' => $data,
'prefix' => '------',
]);
$sortList = ArrayHelper::map($sort->getList(), 'id', 'title');
return $sortList;
}
}
class SortList extends Object
{
public $data;
public $prefix = ' ';
protected function getPath($category_id, $prefix = false)
{
foreach ($this->data as $item) {
if ($category_id == $item['id']) {
$prefix = $prefix ? $this->prefix . $prefix : $item['title'];
if ($item['parent_id']) {
return $this->getPath($item['parent_id'], $prefix);
} else {
return $prefix;
}
}
}
return '';
}
public function getList($parent_id = 0)
{
$data = [];
foreach ($this->data as $item) {
if ($parent_id == $item['parent_id']) {
$data[] = [
'id' => $item['id'],
'title' => $this->getPath($item['id'])
];
$data = array_merge($data, $this->getList($item['id']));
}
}
return $data;
}
}
public function actionCreate()
{
$model = new Menu();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}