本文整理汇总了PHP中app\models\Users::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Users::findOne方法的具体用法?PHP Users::findOne怎么用?PHP Users::findOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Users
的用法示例。
在下文中一共展示了Users::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendMailToAuthor
public function sendMailToAuthor($news, $subject)
{
$user = \app\models\Users::findOne($news->user_id);
$body = sprintf('%s <br />
Ссылка на новость - %s', $subject['author'], $this->urlToNews($news->id));
$this->sendMail($user->email, $subject['author'], $body);
}
示例2: search
/**
* Creates data provider instance with search query applied
*
* @param null $user_id
* @param null $group_id
* @throws \yii\web\NotFoundHttpException
* @return ActiveDataProvider
*/
public function search($user_id = null, $group_id = null)
{
$query = Beacons::find();
if (!Yii::$app->user->can(RbacController::admin)) {
$user = Users::getLogged(true);
$user->getBeaconsQuery($query);
}
if ($user_id !== null) {
$user = Users::findOne(['id' => $user_id]);
$user->getBeaconsQuery($query);
}
if ($group_id !== null) {
$group = Groups::findOne(['id' => $group_id]);
$query = $group->getBeacons();
}
$dataProvider = new ActiveDataProvider(['query' => $query]);
if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'minor' => $this->minor, 'major' => $this->major]);
$query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'uuid', $this->uuid]);
return $dataProvider;
}
示例3: actionAjax
public function actionAjax()
{
$resultArray = array(2 => 0, 131 => 0, 25 => 0);
$words = (new \yii\db\Query())->select(['translateWord', 'wordTranslate', 'typeWord', 'flashCards'])->from('users')->where(['userId' => $this->userId])->one();
foreach ($resultArray as $key => $value) {
if (strpos($words['flashCards'], "|{$key}|")) {
$words['flashCards'] = str_replace("|{$key}|", "|", $words['flashCards']);
}
}
$wordsModel = Users::findOne($this->userId);
$wordsModel->flashCards = $words['flashCards'];
if ($wordsModel->update()) {
echo 'ok';
} else {
echo 'no';
}
// if (Yii::$app->request->isAjax) {
// $success = true;
// foreach ($_POST['ajaxData'] as $key => $value) {
// $words = Vocabulary::findOne($key);
// if (!$words->updateCounters(['Learned' => $value])){
// $success = false;
// }
// }
// if (!$success){
// echo 'Your session progress has successfully been saved';
// }else echo 'Your session progress has not been saved! An error has occured during proccessing';
// }
}
示例4: actionCreate
/**
* Creates a new Exchange model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Exchange();
if ($model->load(Yii::$app->request->post())) {
if ($model->beforeValidate()) {
if ($model->selectorIncomeExpenses == 'income') {
$model->expenses = 0;
$model->income = $model->inputIncomeExpenses;
} else {
$model->income = 0;
$model->expenses = $model->inputIncomeExpenses;
}
if ($model->create_time) {
false;
} else {
$model->create_time = date('Y-m-d');
}
}
$users = Users::findOne(Yii::$app->user->id);
$location = $users->location_id;
$model_report = $model->updateReport($location, $model->create_time, $model->currency, $model->income, $model->expenses, $model->transaction, $model->bo);
$model->location_id = $location;
$model->save();
$model_report->save();
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例5: execute
public function execute($user, $item, $params)
{
$user_role = Users::findOne($user)->authAssignments->item_name;
if (isset($params['news'])) {
$news_status = $params['news']->status;
$news_category = $params['news']->category_id;
$relCat = !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news_category]));
if ($user_role == 'moderator' && $relCat && isset($params['action']) && $params['action'] == 'view') {
return true;
}
if ($news_status == News::MODER_NEWS) {
if ($user_role == 'moderator') {
return $relCat;
}
}
if ($news_status == News::SMODER_NEWS) {
if ($user_role == 'super_moderator') {
return true;
}
}
} elseif (isset($params['question'])) {
if ($user_role == 'moderator') {
$news = News::findOne($params['question']->news_id);
if (!is_null($news)) {
if ($news->status == News::MODER_NEWS && !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news->category_id]))) {
return true;
}
}
}
}
return false;
}
示例6: actionConfirm
public function actionConfirm()
{
$table = new Users();
if (Yii::$app->request->get()) {
//Obtenemos el valor de los parámetros get
$id = Html::encode($_GET["id"]);
$authKey = $_GET["authKey"];
if ((int) $id) {
//Realizamos la consulta para obtener el registro
$model = $table->find()->where("id=:id", [":id" => $id])->andWhere("authKey=:authKey", [":authKey" => $authKey]);
//Si el registro existe
if ($model->count() == 1) {
$activar = Users::findOne($id);
$activar->activate = 1;
if ($activar->update()) {
echo "Enhorabuena registro llevado a cabo correctamente, redireccionando ...";
echo "<meta http-equiv='refresh' content='8; " . Url::toRoute("site/login") . "'>";
} else {
echo "Ha ocurrido un error al realizar el registro, redireccionando ...";
echo "<meta http-equiv='refresh' content='8; " . Url::toRoute("site/login") . "'>";
}
} else {
//Si no existe redireccionamos a login
return $this->redirect(["site/login"]);
}
} else {
//Si id no es un número entero redireccionamos a login
return $this->redirect(["site/login"]);
}
}
}
示例7: findModel
/**
* Finds the Users model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Users the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Users::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例8: findByUsername
static function findByUsername($username)
{
$user = Users::findOne(['username' => $username]);
if ($user) {
return new static($user);
}
return null;
}
示例9: findModel
public function findModel($id)
{
if (($model = Users::findOne($id)) != null) {
return $model;
} else {
throw new NotFoundHttpException('gak iso bos, ojo dipekso');
}
}
示例10: findIdentity
public static function findIdentity($id)
{
try {
$user = Users::findOne($id);
return $user ? new static($user) : false;
} catch (Exception $e) {
return false;
}
}
示例11: findModel
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Users::findOne($id)) !== null) {
return $model;
} else {
$this->getHeader(400);
echo json_encode(['status' => 0, 'error_code' => 400, 'message' => 'Bad request'], JSON_PRETTY_PRINT);
exit;
// throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例12: login
/**
* Logs in a user using the provided username and password.
* @return boolean whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
$model = Users::findOne(['mail' => $this->username]);
$model->ip = \Yii::$app->getRequest()->getUserIP();
$model->agent = \Yii::$app->getRequest()->getUserAgent();
$model->last_login = new yii\db\Expression("NOW()");
$model->save();
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
}
return false;
}
示例13: actionView
public function actionView($link)
{
/** @var Users $user */
$user = Users::findOne(['link' => $link]);
if (!$user) {
throw new NotFoundHttpException('Неверная ссылка или проект удален');
}
Yii::$app->session->set('user', $user);
$project = $user->project;
$photos = $user->photos;
return $this->render('view', ['user' => $user, 'project' => $project, 'photos' => $photos]);
}
示例14: createClassInfo
public function createClassInfo($model)
{
// 获取专业的中文名
$majorid = substr($model->st_class, 0, 4);
$major = Major::findOne($majorid);
$model->class_major = $major->mj_name_zh;
// 获取专业级数
$model->class_year = '20' . substr($model->st_class, 4, 2) . '级';
// 获取辅导员姓名
$user = Users::findOne($model->teID);
$model->te_name = $user->te_name;
return $model;
}
示例15: actionMyWishlist
public function actionMyWishlist()
{
try {
$id = Yii::$app->session['user_id'];
if (empty($id)) {
$this->redirect('http://bluebee-uet.com');
}
$data = Documents::getDocumentsByWishlist($id);
$user = Users::findOne(['id' => $id]);
Yii::$app->view->title = $user->name . ', đây là tài liệu bạn đã đánh dấu';
return $this->render('//document/documents', $data);
} catch (Exception $ex) {
}
}