window.localStorage.setItem('name', 'Obaseki Nosa');
function actionIndex()
{
$query = Article::find()->where(['status' => 1]);
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count()]);
$models = $query->offset($pages->offset)
->limit($pages->limit)
->all();
return $this->render('index', [
'models' => $models,
'pages' => $pages,
]);
}
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBasicAuth::className(),
'auth' => function ($username, $password)
{
;
if ($user=User::find()->where(["username"=>$username])->one() and !empty($password) and $user->validatePassword($password)) {
return $user;
}
else {
return null;
}
},
];
return $behaviors;
}