我正在使用xampp for windows 8,我最近安装了dektrium/yii2-user.我按照安装说明进行操作:
https://github.com/dektrium/yii2-user/blob/master/docs/installation.md
Run Code Online (Sandbox Code Playgroud)
我的web.php的改变部分现在看起来像这样:
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
'class' => 'dektrium\user\Module',
],
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Missing required parameter "id" when instantiating "dektrium\user\Module".
Run Code Online (Sandbox Code Playgroud)
当我删除
'class' => 'dektrium\user\Module',
Run Code Online (Sandbox Code Playgroud)
错误消失了.
我正在使用Yii2并尝试在我的用户名上实现规则,以便始终存储它们并以小写形式进行比较.如果有规则我可以用来实现这个目标吗?
例如,我有一个函数来检查数据库中是否存在用户名.我想避免逻辑错误并尽可能实现全局规则.谢谢你的任何提示!
Yii2规则:
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'password'], 'required'],
[['access_level'], 'integer'],
[['username'], 'string', 'max' => 50], // force lowercase?
[['username_print'], 'string', 'max' => 50],
[['password'], 'string', 'max' => 512],
[['email'], 'string', 'max' => 250],
[['username'], 'unique']
];
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Yii2,GoogleOAuth和yii2用户扩展.我想接收用户谷歌圈子并将范围设置为我的配置:
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'google' => [
'class' => 'yii\authclient\clients\GoogleOAuth',
'clientId' => '758709912345-p4qp4lqihit5un1u6qb75msqp5m5j6d8.apps.googleusercontent.com',
'clientSecret' => 'ZygOIi1-0asfktUQ1pKOFOo',
'scope' => 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/drive',
],
],
]
Run Code Online (Sandbox Code Playgroud)
当我使用Google OAuth2登录时出现错误:
异常 - yii\authclient\InvalidResponseException请求失败,代码:400,消息:{"error":"redirect_uri_mismatch"}
谷歌回应:
[
'url' => 'https://accounts.google.com/o/oauth2/token'
'content_type' => 'application/json'
'http_code' => 400
'header_size' => 435
'request_size' => 644
'filetime' => -1
'ssl_verify_result' => 0
'redirect_count' => 0
'total_time' => 0.115431
'namelookup_time' => 0.001186
'connect_time' => 0.025188
'pretransfer_time' => 0.076275
'size_upload' => 456
'size_download' => 39
'speed_download' …Run Code Online (Sandbox Code Playgroud) 我正在构建一个基于Yii2高级模板的产品.
作为此产品及其未来部署的一部分,我尝试在常规Yii2迁移中自动创建与授权相关的表.
例如,当最终用户安装产品并运行常规Yii迁移命令时,他应该具有活动的全功能用户管理和授权.
要获得授权,Yii2 RBAC文档页面指出需要4个表(auth_*).文档声明它们是通过运行以下迁移创建的:
yii migrate --migrationPath=@yii/rbac/migrations
我想通过在将要存储的常规迁移中为他运行此特定迁移代码来抵消最终用户的这种额外麻烦common/migrations.
对此有什么简单的解决方案
我使用访问控制过滤器进行访问管理,但无法完成一件事 - 例如,我如何才能让项目经理更新项目并禁止其他人?我通过matchCallback尝试了它,但在这种情况下,所有项目经理都可以更新任何项目,因为返回了TRUE.
类似的更常用的规则 - 如何允许用户使用ACF更新/删除他是作者的帖子?
'access' => [
'class' => AccessControl::className(),
'only' => ['index', 'view', 'create', 'update', 'delete'],
'rules' => [
[
'actions' => ['update'],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->getProjectParticipants()
->one()->isManager(Yii::$app->user->identity->id);
}
],
],
],
Run Code Online (Sandbox Code Playgroud) 我试图在yii2空闲一段时间后自动注销用户.在web.php我补充说
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
'authTimeout'=>100
],
Run Code Online (Sandbox Code Playgroud)
在里面components.我正在使用基本模板.但它没有自动退出.这在Yii2中有用吗?我正在关注http://www.yiiframework.com/doc-2.0/yii-web-user.html上的文档
在yii2中,如何在不修改原始视图文件的情况下自定义供应商视图文件?
我正在使用dektrium yii2-user,并希望对登录页面进行一些更改.
这是我的实际查询-
$dataProvider = new ActiveDataProvider([
'query' => UserProfile::find()->with(['user'])
]);
Run Code Online (Sandbox Code Playgroud)
用户表中存在“ 状态 ”字段。所以我想按状态!= 0过滤数据,但是失败。
我试过了-
1个
$dataProvider = new ActiveDataProvider([
'query' => UserProfile::find()->with(['user'])->where('user.status !=',0)
]);
Run Code Online (Sandbox Code Playgroud)
2
$dataProvider = new ActiveDataProvider([
'query' => UserProfile::find()->with(['user'])->where('<>','user.status',0)
]);
Run Code Online (Sandbox Code Playgroud)
没有一个有效。请让我怎么可能?
在我的基本应用项目中,我正在尝试集成注册表单,但出现此错误:
无效的验证规则:规则必须同时指定属性名称和验证器类型。
我的代码在这里。
注册表格.php
<?php
namespace app\models;
use yii\base\Model;
use app\models\User;
/**
* Signup form
*/
class SignupForm extends Model
{
public $user_fname;
public $user_email;
public $user_password_hash;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_fname','user_email', 'user_password_hash'], 'required'],
// rememberMe must be a boolean value
['user_password_hash','match','pattern'=>'$\S*(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$','message'=>'Password must have atleast 1 uppercase and 1 number '],
[['user_password_hash'],'string','min'=>6],
//email validation
['user_email','email']
[['user_email'], 'string', 'max' => 255],
[['user_fname'], 'string', 'max' => 45],
];
}
/**
* Signs user up.
*
* …Run Code Online (Sandbox Code Playgroud) 我必须使用
namespace common\models;
use Yii;
use yii\db\ActiveQuery;
class Addfindcondition extends ActiveQuery
{
public function init()
{
$this->andOnCondition([$this->modelClass::tableName() . '.branch_id' => Yii::$app->user->identity->branch_id ]);
parent::init();
}
}
Run Code Online (Sandbox Code Playgroud)
并像这样分别调用每个模型中的方法
public static function find()
{
return new Addfindcondition(get_called_class());
}
Run Code Online (Sandbox Code Playgroud)
现在我想全局覆盖 find 方法。我怎么可能不需要在每个模型中使用这个静态方法