本文整理汇总了PHP中frontend\models\User::find方法的典型用法代码示例。如果您正苦于以下问题:PHP User::find方法的具体用法?PHP User::find怎么用?PHP User::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frontend\models\User
的用法示例。
在下文中一共展示了User::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'status' => $this->status,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'username', $this->username])
->andFilterWhere(['like', 'user_type', $this->user_type])
->andFilterWhere(['like', 'auth_key', $this->auth_key])
->andFilterWhere(['like', 'password_hash', $this->password_hash])
->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])
->andFilterWhere(['like', 'email', $this->email]);
return $dataProvider;
}
示例2: myValidatePassword
/**
* @param $attribute
* @param $params
* @return bool
*/
public function myValidatePassword($attribute, $params)
{
$model = User::find()->where(['username' => $this->username])->andWhere(['status' => 1])->one();
if (!empty($model) && $model->setPassword($this->{$attribute}) == $model->password) {
return true;
}
$this->addError($attribute, 'The username or password is error!');
}
示例3: validateOriginalPassword
/**
* @param $attribute
* @param $params
* @return bool
*/
public function validateOriginalPassword($attribute, $params)
{
$model = User::find()->where(['username' => Yii::$app->session['username']])->one();
if (!empty($model) && $this->{$attribute} == $model->password) {
return true;
}
$this->addError($attribute, 'The original password is error!');
}
示例4: findModelByUsername
/**
* @return array|null|\yii\db\ActiveRecord
* @throws NotFoundHttpException
*/
public static function findModelByUsername()
{
if ($username = Yii::$app->session['__username']) {
if (($model = User::find()->where(['username' => $username])->one()) !== null) {
return $model;
}
}
throw new NotFoundHttpException('The requested page does not exist.');
}
示例5: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'category' => Category::find()->all(), 'authors' => User::find()->all()]);
}
}
示例6: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['like', '_id', $this->_id])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'user_role', $this->user_role])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'created_at', $this->created_at])->andFilterWhere(['like', 'updated_at', $this->updated_at]);
return $dataProvider;
}
示例7: actionCreate
/**
* @return \yii\web\Response
*/
public function actionCreate()
{
$model = new Comment();
$model->ip = Yii::$app->request->userIP;
$model->username = Yii::$app->session['__username'];
$model->user_id = User::find()->where(['username' => $model->username])->one()->id;
$model->created_at = time();
$model->updated_at = time();
//$params = FilterForm::filterHtml();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['show/view', 'id' => $model->news_id]);
}
echo '发布失败,请重新发表评论!';
}
示例8: search
/**
* @param $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find()->orderBy('created_at DESC');
$dataProvider = new ActiveDataProvider(['query' => $query]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
if ($this->created_at !== null) {
$date = strtotime($this->created_at);
$query->andFilterWhere(['between', 'created_at', $date, $date + 3600 * 24]);
}
$query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['registration_ip' => $this->registration_ip]);
return $dataProvider;
}
示例9: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
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, 'role' => $this->role, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
$query->andFilterWhere(['like', 'fname', $this->fname])->andFilterWhere(['like', 'lname', $this->lname])->andFilterWhere(['like', 'contact_no', $this->contact_no])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'company_name', $this->company_name])->andFilterWhere(['like', 'company_description', $this->company_description])->andFilterWhere(['like', 'shipping_address', $this->shipping_address])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email]);
return $dataProvider;
}
示例10: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id, 'role' => $this->role, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'data_nasc' => $this->data_nasc]);
$query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'nome', $this->nome])->andFilterWhere(['like', 'sexo', $this->sexo])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'endereco', $this->endereco])->andFilterWhere(['like', 'complemento', $this->complemento])->andFilterWhere(['like', 'instituicao', $this->instituicao])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'grupoacesso', $this->grupoacesso])->andFilterWhere(['like', 'cpf', $this->cpf]);
return $dataProvider;
}
示例11: findByUsername
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
$user = User::find()->where(['username' => $username])->asArray()->one();
if ($user) {
return new static($user);
}
return null;
/*foreach (self::$users as $user) {
if (strcasecmp($user['username'], $username) === 0) {
return new static($user);
}
}
return null;*/
}
示例12: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'mobile_number' => $this->mobile_number, 'mobileNumber' => $this->mobileNumber]);
$query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'addressImage', $this->addressImage]);
return $dataProvider;
}
示例13: steamAuth
/**
* Authencticate or create and authenticate user
*
* @param \frontend\components\SteamAuth $client
*/
public function steamAuth($client)
{
$user = User::find()->where(['steamid' => $client->steamId])->one();
if (Yii::$app->user->isGuest) {
if ($user) {
Yii::$app->user->login($user);
return $this->redirect(['site/index']);
}
$user = User::createSteamUser($client);
if (!$user) {
throw new Exception("Не получилось создать пользователя :(", 500);
}
return $this->redirect(['site/index']);
}
return $this->redirect(['site/index']);
}
示例14: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
if (Yii::$app->user->identity->rol_id == '2') {
$query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'rol_id' => $this->rol_id, 'supervisor' => $this->supervisor, 'id_organizacion' => $this->id_organizacion, 'id_empresa' => $this->id_empresa, 'id_distrito' => $this->id_distrito])->orderBy(['username' => SORT_ASC]);
} else {
$query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'rol_id' => '1', 'supervisor' => $this->supervisor, 'id_organizacion' => $this->id_organizacion, 'id_empresa' => $this->id_empresa, 'id_distrito' => $this->id_distrito])->orderBy(['username' => SORT_ASC]);
}
$query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'apellido', $this->apellido])->andFilterWhere(['like', 'cedula', $this->cedula]);
return $dataProvider;
}
示例15: beforeSave
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
// ...custom code here..
//unread初始值为所有接收人,添加未阅读的用户id
if ($insert) {
$user = User::find()->select('id')->asArray()->all();
$user = ArrayHelper::getColumn($user, 'id');
$this->unread = implode(',', $user);
//将deleted初始值设置为0,防止该字段为null
$this->deleted = 0;
}
//...custom code end
return true;
} else {
return false;
}
}