-->
Boshqaruv qismi.
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\Response;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;
use app\models\User;
use app\models\Book;
use app\models\News;
use yii\web\UploadedFile;
use yii\data\Pagination;
class PostController extends SiteController
{
public function actionIndex()
{
$books = Book::find()->limit(4)->all();
return $this->render('index',compact('books'));
}
public function actionBooks(){
$book = Book::find();
$page = new Pagination([
'pageSize' => 4,
'totalCount' => $book->count(),
'forcePageParam' => false,
'pageSizeParam' => false
]);
$books = $book->offset($page->offset)->limit($page->limit)->all();
return $this->render('books', compact('books','page'));
}
public function actionAbout(){
return $this->render('about');
}
public function actionNewsView(){
$id = Yii::$app->request->get('id');
$news = News::findOne($id);
return $this->render('news-view',compact('news')
public function actionLibrary(){
$news = News::find();
$page = new Pagination([
'pageSize' => 3,
'totalCount' => $news->count(),
'forcePageParam' => false,
'pageSizeParam' => false
]);
$news = $news->offset($page->offset)->limit($page->limit)->all();
return $this->render('library',compact('news','page'));
}
public function actionContact(){
$this->layout = false;
$model = new User();
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
}
else{
}
}
return $this->render('contact', compact('model'));
}
public function actionBooksCreate(){
$this->layout = false;
$model = new Book();
if ($model->load(Yii::$app->request->post())) {
$model->img = UploadedFile::getInstance($model, 'img');
if ($model->img && $model->validate()) {
$model->img->saveAs('images/kitob/' . $model->img->baseName . '.' . $model->img->extension);
}
$model->save();
// echo "
";
// print_r($model);
// echo "
";
return $this->redirect(['post/books']);
}
return $this->render('create',compact('model'));
}
public function actionKirish(){
$this->layout = false;
// $model = new User();
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
$model->password = '';
return $this->render('login', [
'model' => $model,
])
}
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}