安装yii2 composer token是,提示要输入token,是什么鬼

问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
yii2中登录需要通过 User::validateAuthKey() 来检测数据库中是否存在这个,文件@app/vendor/yiisoft/yii2/web/User.php ,也就是说,要使用Yii2自带的用户认证功能,设计的用户表必须包含 userid username authkey pwd 这几样字段,但问题是 authkey 这个随机码是什么时候更新?
文件@app/vendor/yiisoft/yii2/web/User.php 全部源码:
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
首先呢,authKey不一定非要存在用户表里,我就是单独用一个表存的,这个是用来验证自动登录cookie的合法性的。更新呢:\yii\web\User有个beforeLogin事件,在事件里完成更新
authKey表字段如下:
key varchar
User Model如下:
* 用户authKey关联对象
public function getAuthModel()
return $this-&hasOne(AuthKey::className(), ['uid' =& 'id']);
* 生成authkey
* 自动登录时,cookie中的authkey
public function generateAuthKey() {
$model = $this-&authM
if (!$model) {
$model = new AuthKey();
$model-&uid = $this-&
$model-&key = Yii::$app-&security-&generateRandomString(32);
$model-&save(false);
//实现接口
public function getAuthKey() {
return $this-&authModel-&
以上是authKey的生成方法然后登录动作里,监听before_login事件
Yii::$app-&user-&on(\yii\web\User::EVENT_BEFORE_LOGIN, [$this-&user, 'generateAuthKey']);
这样,每次主动登录,authKey都会更新
Token一般是restfull做接口才用到,更新方法类似
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
authkey是用于你给用户一个链接,用于可以直接点击这个链接就能登陆的,如果没有这个,可以不要这个字段和功能
同步到新浪微博
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:YII2 composer安装遇到的问题解决 - 话题 - Yii Framework 中文社区
YII2 composer安装遇到的问题解决
2131次浏览
很少发帖,因为YII2.0.7的安装,走了一些坑,和大家分享一下
win7下YII2安装:
1.下载yii2.0.7安装包...
2.安装composer...
3.cd advanced, 执行composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced ../yii2test
这是如果有报错,没有对应的资源(安装成功,忘记截图了)
The "fxp/composer-asset-plugin" plugin requires composer-plugin-api 1.0.0, this *WILL* break in the future and it should be fixed ASAP
require ^1.0 for example).
PHP Fatal error:
Call to undefined method Fxp\Composer\AssetPlugin\Package\Version\VersionParser::parseLinks() in C:\Users\v_xiexiaoqing\AppData\Roaming\Composer\vendor\fxp\composer-asset-plugin\Repository\VcsPackageFilter.php on line 272
Fatal error: Call to undefined method Fxp\Composer\AssetPlugin\Package\Version\VersionParser::parseLinks() in C:\Users\v_xiexiaoqing\AppData\Roaming\Composer\vendor\fxp\composer-asset-plugin\Repository\VcsPackageFilter.php on line 272
执行 composer global require "fxp/composer-asset-plugin:~1.1.1"
更新成最新的
执行完后 再执行 composer update 这时就能下载最新的资源了,中间会出现让输入token的提示
到/settings/tokens(没有账号,就注册一个)获取token,输入后,继续下载资源
下载完后,再次执行composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced ../yii2test, 如果没有报错就安装成功了
4.cd ../yii2test 执行init
支持分享。
和文档中好像没有区别。
另外,第一步是干嘛用的?
共 4 条回复
文档中安装好像没有composer update, 不知道为什么, 不执行这个命令,资源就不会下载,还是说已经配置了,第一步当然是现在yii2了... ...
问题是你下载下来的yii2包后面没有用上呢
对,很可能用不上,这样create的时候会有一些报错信息,应该不影响
这个做什么用?
您需要登录后才可以回复。 |官方文档给出了比较详细的教程,我在windows和MacBook都安装了一下,在过程中出现了两个小问题,文档都没给出(第一个问题是描述不清晰),在此总结一下。
安装的过程大致为:
1.安装composer,PHP 的一个依赖管理工具。
2.根据composer的命令来安装yii。
确实是比较简单,过程中出现的两个问题是:
1.在安装yii的过程要你输入一个Token。
解决方式:(提示已有给出)
让你去这个地址获取一个token,如果没有github账号要先注册再登录。进入该页面只需点击下面的按钮,然后复制token黏贴到终端就可以了。
2.安装yii结束后访问工程出错,报错如下:
Invalid Parameter&–&
立马就找到答案:
Inside vendor/bower folder it's another one called bower-asset. Copy this folder content (some other
folders named bootstrap, jquery, etc...) and move them to vender/bower.
原链接:/questions//installing-yii2-invalid-parameter-yii-base-invalidparamexception
只需要把vendor/bower/bower-asset里面的文件夹移动到vendor/bower下,就可以啦。
it !!!!!!!
本文已收录于以下专栏:
相关文章推荐
在安装yii2框架的时候,遇到一个很纠结的问题。就是当我把安装包下载下来之后,在公司的电脑安装可以正常,当我回家用自己的电脑安装就报错,提示php.exe 不是内部或外部命令,也不是可运行的程序。这下...
在Yii2的basic版本中默认是从一个数组验证用户名和密码,如何改为从数据表中查询验证呢?且数据库的密码要为哈希加密密码验证?
下面我们就一步一步解析Yii2的登录过程。
一. 创建user表模型
使用gii生成用户表的model生成的几个方法解析:
随机数生成
protected function generateSalt($cost = 13)
初学Spring框架,遇到的小问题总结经验!
今天在写一个小程序中遇到一个问题,我想在两个类中相互持有引用,比如:
1. 一个类是画板,另一个类是画板中一个图形;
2. 画板必须持有图形的引用才能绘制图形;
3. 图形希望能够根据自身一些属性改变...
他的最新文章
讲师:李江龙
讲师:司徒正美
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)Yii2 的注册登陆实现 - 教程 - Yii Framework 中文社区
Yii2 的注册登陆实现
31552次浏览
首先看SiteController.php
以下是必须引入的
use frontend\models\SiteLoginF
use frontend\models\U
use frontend\models\SignupF
public function actionSignup()
$model = new SignupForm();
if ($model-&load(Yii::$app-&request-&post())) {
if ($user = $model-&signup()) {
// $login = new SiteLoginForm();
if(Yii::$app-&getUser()-&login($user)) {
return $this-&goHome();
var_dump($user);
return $this-&render('signup', [
'model' =& $model,
public function actionLogin()
if (!\Yii::$app-&user-&isGuest) {
return $this-&goHome();
$model = new SiteLoginForm();
if ($model-&load(Yii::$app-&request-&post()) && $model-&login()) {
return $this-&goBack();
return $this-&render('login', [
'model' =& $model,
frontend/models/User.php文件
namespace frontend\
use yii\web\IdentityI
class User extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
* @inheritdoc
public static function tableName()
return 'shop_user';
* @inheritdoc
public function rules()
[['username', 'pwd', 'create_time'], 'required'],
[['create_time'], 'integer'],
[['username'], 'string', 'max' =& 20],
[['pwd'], 'string', 'max' =& 32]
* @inheritdoc
public function attributeLabels()
'id' =& 'ID',
'username' =& 'Username',
'pwd' =& 'Pwd',
'create_time' =& 'Create Time',
* Generates password hash from password and sets it to the model
* @param string $password
public function setPassword($password)
$this-&pwd = md5($password);
* @inheritdoc
public static function findIdentity($id)
return static::findOne($id);
//return isset(self::$users[$id]) ? new static(self::$users[$id]) :
* @inheritdoc
public static function findIdentityByAccessToken($token, $type = null)
return static::findOne(['access_token' =& $token]);
/*foreach (self::$users as $user) {
if ($user['accessToken'] === $token) {
return new static($user);
* Finds user by username
* @return static|null
public static function findByUsername($username)
$user = User::find()
-&where(['username' =& $username])
-&asArray()
if($user){
return new static($user);
/*foreach (self::$users as $user) {
if (strcasecmp($user['username'], $username) === 0) {
return new static($user);
* @inheritdoc
public function getId()
return $this-&
* @inheritdoc
public function getAuthKey()
return $this-&authK
* @inheritdoc
public function validateAuthKey($authKey)
return $this-&authKey === $authK
* Validates password
$password password to validate
* @return boolean if password provided is valid for current user
public function validatePassword($password)
return $this-&pwd === md5($password);
config/main.php代码
'components' =& [
'user' =& [
'identityClass' =& 'frontend\models\User',
'enableAutoLogin' =& true,
SignupForm.php代码
//注意这里的规则由你自己定义有几个地段哈
public function rules()
['username', 'filter', 'filter' =& 'trim'],
['username', 'required','message' =& '用户名不能为空'],
['username', 'unique', 'targetClass' =& '\frontend\models\User', 'message' =& '用户名已存在'],
['username', 'string', 'min' =& 2, 'max' =& 255],
['password', 'required','message' =& '密码不能为空'],
['password', 'string', 'min' =& 6],
//注意这个方法里user表的字段
public function signup()
if ($this-&validate()) {
$user = new User();
$user-&username = $this-&
$user-&setPassword($this-&password);
$user-&create_time = time();
if ($user-&save()) {
,准备借助yiichina里的教程,编辑成一本书,最后用某高校LaTeX论文模板美化一下,每月或者更长时间发布PDF教程总结,求支持。
我想把你的教程录入到这本书里,并记录您的名字及原网址,可否?谢谢啦。
共 3 条回复
厉害、当然可以、技术这东西
就是要分享
就是要分享
请问 gohome
和 那个 goback
有什么用的·
共 2 条回复
gohome 回主页
返回上一页
这个主页是哪里?可以自定义吗?
请问这个是基础模板的登陆,还是高级模板的登陆?
共 1 条回复
高级模版里的
SiteLoginForm类代码没有,跪求
SiteLoginForm类代码没有,跪求
这是高级版吗
return 'shop_user';
shop_user是什么?
共 1 条回复
数据表名。。
setpassword()
方法不用return 吗?
您需要登录后才可以评论。 |yii2 安装 - 教程 - Yii Framework 中文社区
132078次浏览
这些天看了一下,发现还有很多人对yii2安装存在许多问题,在网上搜了很多资料,才发现他们都很不全面,以至于走了很多弯路,
下面我把完整的安装流程介绍给大家:按照这个流程走,相信你一定可以成功!
总感觉这个教程排版都很靠左,感觉这个样式排版不好的话,可以去我的博客看:
希望对你们有帮助!
前提:非常重要,你的php版本必须是php5.4以上
1.首先需要下载应用模板,分为基础模板和高级应用模板,这里我以高级应用模板为例子 :
去这里现在高级应用模板
2.下载完之后解压放在www目录我是放在 D:\wamp\www\yii2\advanced
cmd dos命令进入这个D:\wamp\www\yii2\advanced下:
3.运行 php -r "readfile('https://getcomposer.org/installer');" | php
4.这是就在D:\wamp\www\yii2\advanced目录下面下载了一个composer.phar文件,有了这个文件就可以执行php composer.phar命令了,提示:
5.准备所有插件!!非常重要,少了这步一切都会失败
(记得配置php环境变量啊)
执行命令:php composer.phar global require "fxp/composer-asset-plugin:1.0.0"
6.安装我们的yii2的应用:
执行命令:php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced ../yii2test 就会在上一层目录下生成yii2test应用 。
请注意,到第六步很可能就一直停在那里了,这个时候,登录GitHub的用户名和密码没有就注册个账号,退出cmd,重新执行第6步可。
若提示安装过程中输入你的 GitHub 的用户名和密码。那就输入它们并继续即可。现在可能是输入token了
7.最后一步:初始化我们的应用,初始化是在你创建的yii2test目录下
init命令 选0
ok,这么我们的yii2的安装就完成了,进入测试目录:localhost/yii2/yii2test/frontend/web/index.php
会看到如下界面:
这就表明的你的yii2安装成功了,一定要记住你的php版本是php5.4以上的!
收藏。。。
![F846V6D2UL1SN$$B0I9]T0J.png](/uploads/images/.png "F846V6D2UL1SN$$B0I9]T0J.png")
请问这是什么问题????急
D:\wamp64\www\yii2\advanced&php composer.phar global require "fxp/composer-asset-plugin:1.0.0-beta3"
Changed current directory to C:/Users/boyu/AppData/Roaming/Composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Failed to decode response: zlib_decode(): data error
Retrying with degraded mode, check
for more info
环境变量配的是什么啊
第五步 就一直Updating dependencies (including require-dev)
百度了下说是要弄个镜像,不然连不上国外的链接
好人一生平安!
我就想问你们下载的有Vendor目录么
厉害了,我的哥
第五步出错如何处理呢
过来看看的啊
composer global require fxp/composer-asset-plugin --no-plugins
在第一步不是已经下载了高级版的包了么,为什么在后面的步骤里面又要从github下载包呢?? 没看懂,求大神指点下
共 1 条回复
同感,希望有大神出来指点下.
为什么我按照上面的步骤操作后,项目文件夹下没有:vendor 这个文件夹和这个文件夹下的相关文件?
共 1 条回复
你指的composer global require "fxp/composer-asset-plugin:~1.1.1" ,只操作了这一步?
第五步的时候出错了
C:\wamp\www\yii2\advanced&php composer.phar global require "fxp/composer-asset-plugin:1.0.0"
Changed current directory to C:/Users/Floruit/AppData/Roaming/Composer
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
- Installation request for fxp/composer-asset-plugin 1.0.0 -& satisfiable by fxp/composer-asset-plugin[v1.0.0].
- fxp/composer-asset-plugin v1.0.0 requires composer-plugin-api 1.0.0 -& no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see &https://getcomposer.org/doc/04-schema.md#minimum-stability& for more details.
Read &https://getcomposer.org/doc/articles/troubleshooting.md& for further common problems.
Installation failed, deleting ./composer.json.
C:\wamp\www\yii2\advanced&
共 1 条回复
composer global require "fxp/composer-asset-plugin:~1.1.1" 找不到 1.0.0 的包,改成 1.1.1 好了
楼主,第六部出现
- yiisoft/yii2 2.0.x-dev requires bower-asset/jquery.inputmask ~3.2.2 -& no
matching package found.
- yiisoft/yii2 dev-master requires bower-asset/jquery.inputmask ~3.2.2 -& no
matching package found.
- yiisoft/yii2 2.0.8 requires bower-asset/jquery 2.2.*@stable | 2.1.*@stable
| 1.11.*@stable -& no matching package found.
- yiisoft/yii2 2.0.7 requires bower-asset/jquery 2.2.*@stable | 2.1.*@stable
| 1.11.*@stable -& no matching package found.
- yiisoft/yii2 2.0.6 requires bower-asset/jquery 2.1.*@stable | 1.11.*@stabl
e -& no matching package found.
- Installation request for yiisoft/yii2 &=2.0.6 -& satisfiable by yiisoft/yi
i2[2.0.6, 2.0.7, 2.0.8, dev-master, 2.0.x-dev].
Potential causes:
A typo in the package name
The package is not available in a stable-enough version according to your min
imum-stability setting
for more det
for further commo
n problems.
请问这个是什么问题呢?求解。
F:\wamp\www\YII2\advanced&php composer.phar global require "fxp/composer-asset-p
lugin:1.0.0"
Changed current directory to C:/Users/Administrator/AppData/Roaming/Composer
You are running composer with xdebug enabled. This has a major impact on runtime
performance. See
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Installing fxp/composer-asset-plugin (v1.0.0)
Loading from cache
The "fxp/composer-asset-plugin" plugin requires composer-plugin-api 1.0.0, thisWILL break in the future and it should be fixed ASAP (require ^1.0 for example
Fatal error: Call to undefined method Fxp\Composer\AssetPlugin\Package\Version\V
ersionParser::parseLinks() in C:\Users\Administrator\AppData\Roaming\Composer\ve
ndor\fxp\composer-asset-plugin\Repository\VcsPackageFilter.php on line 272
Call Stack:
1. {main}() F:\wamp\www\YII2\advanced\composer.phar:0
2. require('phar://F:/wamp/www/YII2/advanced/composer.ph
ar/bin/composer') F:\wamp\www\YII2\advanced\composer.phar:24
3. Composer\Console\Application-&run() phar://F:/wamp/ww
w/YII2/advanced/composer.phar/bin/composer:43
4. Symfony\Component\Console\Application-&run() phar://F
:/wamp/www/YII2/advanced/composer.phar/src/Composer/Console/Application.php:99
5. Composer\Console\Application-&doRun() phar://F:/wamp/
这问题咋办呀,求解~
出了这个错,好蛋疼,求解~
我觉得这个应该标明是windows下的yii2安装,我在linux下用这个装了好久,不成,后来就用
D:\wamp64\www\yii2&php -r "readfile('https://getcomposer.org/installer');" | php
'php' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
为什么我的电脑执行不了这样的命令呢?
按照这个步骤装完后,报错了。。:
Invalid Parameter – yii\base\InvalidParamException
The file or directory to be published does not exist: D:\wamp\www\yii_advanced/vendor\bower/jquery/dist
完成之后访问出现这个问题:Invalid Parameter – yii\base\InvalidParamException
The file or directory to be published does not exist: E:\www\yii2\yii2test1/vendor\bower/jquery/dist
我把这个目录E:\www\yii2\yii2test\vendor\bower\bower-asset下的 jquery/dist拷过来才好了,这是什么原因啊?为什么多一个bower-asset的目录
您需要登录后才可以评论。 |

我要回帖

更多关于 yii2 token验证 的文章

 

随机推荐