• Composer Yii2 不设置全局变量 归档安装 Win7


    1.下载Composer_installer.phar

    https://getcomposer.org/composer.phar

    重命名为  composer_installer.phar

    将文件放入根目录WWW

    2.开启PHP 的 openssl 扩展

    打开对应php版本的php,ini

    去掉注释;

    3.安装Composer

    cmd -> d: -> cd d:/phpstudy/www
    
    php composer_installer.phar
    

    4.设置使用Composer命令

    在 C:/   下创建  initcmdenv.cmd  文件 内容如下

    @echo off
    
    :: Temporary system path(为当前命令行增加额外的PATH,可随意增加不影响全局系统) 
    set PATH=%PATH%;
    
    :: Commands(增加新的快捷命令,必须为DOSKEY 快捷名称=完整命令) 
    DOSKEY composer=php d:/phpstudy/www/composer.phar $*
    
    ::Show something(显示初始化的内容,可以删掉)
    
    echo ========DOSKEY==========
    
    DOSKEY /macros
    
    echo ========END==========
    

     创建  C:WindowsSystem32cmd.exe  快捷方式

    设置开解方式目标为    %windir%/system32/cmd.exe /K C:/initcmdenv.cmd

    设置好后 直接运行这个 cmd.exe 快捷方式 就可以直接在命令行的任何地方直接使用  composer 命令了。

    5.下载 Composer归档包

    2个版本,advanced 和 basic :

    https://github.com/yiisoft/yii2/releases/download/2.0.9/yii-advanced-app-2.0.9.tgz

    https://github.com/yiisoft/yii2/releases/download/2.0.9/yii-basic-app-2.0.9.tgz

     下载后解压缩至根目录 WWW

    在解压的归档包 composer.json 中添加 中国镜像 地址

    {
       "repositories": {
          "packagist": {
            "type": "composer",
            "url": "https://packagist.phpcomposer.com"
          }
        }          
    }
    

     6. require "fxp/composer-asset-plugin:~1.1.1"  查询并添加最新版本

    php composer.phar global require "fxp/composer-asset-plugin:~1.1.1" 
    

     或

    composer global require "fxp/composer-asset-plugin:~1.1.1"
    

    7.创建Yii2项目

    cmd快捷方式 -> d: -> cd d:/phpstudy/www/baisc (advanced)
    

    advanced:

    composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced ../yii2test
    

    basic:

    composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic ../yii2test
    

     8.Token   (github)

    create a new Token

    https://github.com

    MyID:50486****@**.com   Password:23*********

    将得到的Token输入即可。

     

     等待项目创建完成。

    9.在创建的项目内添加phpexcel扩展

    {
      "require": {
            "php": ">=5.4.0",
            "yiisoft/yii2": "~2.0.5",
            "yiisoft/yii2-bootstrap": "~2.0.0",
            "yiisoft/yii2-swiftmailer": "~2.0.0",
            "phpoffice/phpexcel": "dev-develop"
        },
      "config": {
            "process-timeout": 1800,
            "secure-http": false
        },
      "repositories": {
          "packagist": {
            "type": "composer",
            "url": "https://packagist.phpcomposer.com"
          }
        }    
    }
    
    cmd快捷方式 -> d: -> cd d:/phpstudy/www/NewProject
    
    composer update
    

     

    10.使用YII2已写好的demo登录

    User  SQL:

    CREATE TABLE `user` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `username` varchar(32) NOT NULL,
      `email` varchar(32) NOT NULL,
      `password` varchar(32) NOT NULL,
      `authKey` varchar(100) NOT NULL DEFAULT '',
      `accessToken` varchar(100) NOT NULL DEFAULT '',
      PRIMARY KEY (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

    使用gii生成 model User 。

    将Class  User  implements yiiwebIdentityInterface

    内容加上登录验证代码

      /**
         * @inheritdoc
         */
        public static function findIdentity($id)
        {
            return static::findOne($id);
            //return isset(self::$users[$id]) ? new static(self::$users[$id]) : null;
        }
    
        /**
         * @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);
                }
            }
    
            return null;*/
        }
    
        /**
         * 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;*/
        }
    
        /**
         * @inheritdoc
         */
        public function getId()
        {
            return $this->id;
        }
    	
    	/**
    	* get level by username
    	* @param string username 
    	* @return string level
    	*/
        public function getLevelByusername($username)
        {
            $user = User::find()
               ->where(['username' => $username])
               ->asArray()
               ->one();
            return $user['level'];
        }
    
        /**
         * @inheritdoc
         */
        public function getAuthKey()
        {
            return $this->authKey;
        }
    
        /**
         * @inheritdoc
         */
        public function validateAuthKey($authKey)
        {
            return $this->authKey === $authKey;
        }
    
        /**
         * Validates password
         *
         * @param  string  $password password to validate
         * @return boolean if password provided is valid for current user
         */
        public function validatePassword($password)
        {
            return $this->password === $password;
        }
    

     这样设置的User就可以直接登录使用啦。

  • 相关阅读:
    android--从手动存取->View Model->Live Data->Data Binding
    android--------解决Entities and POJOs must have a usable public constructor
    开课第一周周总结
    Pandas Series: sum()方法
    .Net Core/Framework之Nginx反向代理后获取客户端IP等数据探索
    readonly与disabled的区别
    html使用frame框架导航跳转至指定的节的用法
    HTML+Css让网页自动适应电脑手机屏幕
    仿Quora的免费问答网站程序
    WebGL 纹理颜色原理
  • 原文地址:https://www.cnblogs.com/GaoAnLee/p/5881240.html
Copyright © 2020-2023  润新知