本文整理汇总了PHP中app\models\Users::findAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Users::findAll方法的具体用法?PHP Users::findAll怎么用?PHP Users::findAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Users
的用法示例。
在下文中一共展示了Users::findAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendMailToModerator
public function sendMailToModerator($news, $subject)
{
$subquery = (new \yii\db\Query())->select('user_id')->from('relation_categories')->where(['category_id' => $news->category_id]);
$users = Users::findAll(['id' => $subquery]);
foreach ($users as $user) {
$emails[] = $user->email;
}
$body = sprintf('%s <br />
Ссылка на новость - %s', $subject['moderator'], $this->urlToNews($news->id));
$this->sendMail($emails, $subject['moderator'], $body);
}
示例2: actionCreate
/**
* Creates a new MessagesUsers model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new MessagesUsers();
$type = Yii::$app->request->get('type');
if (Yii::$app->request->isPost) {
$param = Yii::$app->request->post();
if ($param['user_type'] == 'user_name') {
$userId = Users::getIdByName($param['MessagesUsers']['users_id']);
if (empty($userId)) {
throw new ServerErrorHttpException('不存在的用户姓名!');
}
$model->messages_id = $param['MessagesUsers']['messages_id'];
$model->type = $param['MessagesUsers']['type'];
$model->users_id = $userId;
$model->content = $param['MessagesUsers']['content'];
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
} elseif ($param['user_type'] == 'user_level') {
$levelId = Level::getIdByName($param['MessagesUsers']['users_id']);
if (empty($levelId)) {
throw new ServerErrorHttpException('不存在的级别名称!');
}
$usersList = Users::findAll(['level_id' => $levelId, 'status' => 1]);
if (!empty($usersList)) {
foreach ($usersList as $key => $val) {
$messagesUsersInfo['messages_id'] = $param['MessagesUsers']['messages_id'];
$messagesUsersInfo['type'] = $param['MessagesUsers']['type'];
$messagesUsersInfo['users_id'] = $val['id'];
$messagesUsersInfo['content'] = $param['MessagesUsers']['content'];
$messagesUsersInfo['create_time'] = date('Y-m-d H:i:s', time());
$messagesUsersInfo['create_user'] = 'admin';
$messagesUsersInfo['update_time'] = date('Y-m-d H:i:s', time());
$messagesUsersInfo['update_user'] = 'admin';
MessagesUsers::addInfo($messagesUsersInfo);
}
return $this->redirect('index');
}
} elseif ($param['user_type'] == 'all_user') {
$usersList = Users::getAll();
if (!empty($usersList)) {
foreach ($usersList as $key => $val) {
$messagesUsersInfo['messages_id'] = $param['MessagesUsers']['messages_id'];
$messagesUsersInfo['type'] = $param['MessagesUsers']['type'];
$messagesUsersInfo['users_id'] = $val['id'];
$messagesUsersInfo['content'] = $param['MessagesUsers']['content'];
$messagesUsersInfo['create_time'] = date('Y-m-d H:i:s', time());
$messagesUsersInfo['create_user'] = admin;
$messagesUsersInfo['update_time'] = date('Y-m-d H:i:s', time());
$messagesUsersInfo['update_user'] = 'admin';
MessagesUsers::addInfo($messagesUsersInfo);
return $this->redirect('index');
}
}
} else {
throw new ServerErrorHttpException('参数错误!');
}
} else {
return $this->render('create', ['model' => $model, 'type' => empty($type) ? '1' : $type]);
}
}
示例3: actionBulkDelete
/**
* Delete multiple existing Users model.
* For ajax request will return json object
* and for non-ajax request if deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionBulkDelete()
{
$request = Yii::$app->request;
$pks = $request->post('pks');
// Array or selected records primary keys
foreach (Users::findAll(json_decode($pks)) as $model) {
$model->delete();
}
if ($request->isAjax) {
/*
* Process for ajax request
*/
Yii::$app->response->format = Response::FORMAT_JSON;
return ['forceClose' => true, 'forceReload' => true];
} else {
/*
* Process for non-ajax request
*/
return $this->redirect(['index']);
}
}