use app\assets\AppAsset;
AppAsset::register($this); // $this - представляет собой объект представления
use app\components\AuthHandler;
class SiteController extends Controller
{
public function actions()
{
return [
'auth' => [
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'onAuthSuccess'],
],
];
}
public function onAuthSuccess($client)
{
(new AuthHandler($client))->handle();
}
}
<?= yii\authclient\widgets\AuthChoice::widget([
'baseAuthUrl' => ['site/auth'],
'popupMode' => false,
]) ?>
$zip = new ZipArchive();
if ($zip->open($file, ZipArchive::CREATE) !== TRUE) {
throw new \Exception('Cannot create a zip file');
}
foreach($files as $file){
$zip->addFile($file[file_name], $file[local_name]);
}
$zip->close();
unlink
, чтобы удалить временный zip.if (Yii::$app->request->isAjax) {
return $this->renderPartial('_list', [
'dataProvider' => $dataProvider,
'checker' => $this->checker
]);
} else {
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'checker' => $this->checker,
'futureCount' => $futureCount,
'pastCount' => $pastCount,
'myCount' => $myCount,
]);
}
<div class="box-body">
<div id="search-content">
<?= $this->render('_list', [
'dataProvider' => $dataProvider,
'checker' => $checker
]) ?>
</div>
</div>
index.php
в котором рендерится_list.php
, там где вы обновляете страницу без перезагрузки контроллер вам выдаст только структуру в _list.php
. После добавлении записи - просто перезагружаете страницу ajax. <?= Yii::$app->formatter->asHtml($model->content, [
'Attr.AllowedRel' => ['nofollow'],
'HTML.SafeObject' => true,
'Output.FlashCompat' => true,
'HTML.SafeIframe' => true,
'AutoFormat.AutoParagraph' => true,
'URI.SafeIframeRegexp' => '%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%',
]) ?>
composer —no-dev
composer —prefer-dist
->cache()
в запросе.$user = Profile::find()->where(["id" => $id])->cache(1000)->asArray()->one();
В других случаях запросы не кэшируются. Иногда, в настройках, устанавливают кэширование схемы: ...
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=****',
'username' => '****',
'password' => '****',
'charset' => 'utf8',
'enableSchemaCache' => false, // Если не нужно кэшировать вместо `true` поставить `false`
'schemaCacheDuration' => 3600,
'schemaCache' => 'cache',
],
...