小编Ram*_*eek的帖子

更新composer抛出异常类Fxp\Composer\AssetPlugin\Repository\NpmRepository不存在

我最近为Yii2基本应用程序模板运行了最新的作曲家安装.

但是运行php composer.phar install抛出了这个异常:

类Fxp\Composer\AssetPlugin\Repository\NpmRepository不存在

"yiisoft/yii2-composer"插件需要composer-plugin-api 1.0.0,这个WIL L在未来中断,应该尽快修复(例如需要^ 1.0).

[ReflectionException]类Fxp\Composer\AssetPlugin\Repository\NpmRepository不存在

[ErrorException]

声明Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository :: w hatProvides()应该与Composer\Repository\ComposerRepository :: whatProvides(Composer\DependencyResolver\Pool $ pool,$ name,$ bypassFilters = fal se)兼容

这是我的composer.json:

{
    "name": "yiisoft/yii2-app-basic",
    "description": "Yii 2 Basic Project Template",
    "keywords": ["yii2", "framework", "basic", "project template"],
    "homepage": "http://www.yiiframework.com/",
    "type": "project",
    "license": "BSD-3-Clause",
    "support": {
        "issues": "https://github.com/yiisoft/yii2/issues?state=open",
        "forum": "http://www.yiiframework.com/forum/",
        "wiki": "http://www.yiiframework.com/wiki/",
        "irc": "irc://irc.freenode.net/yii",
        "source": "https://github.com/yiisoft/yii2"
    },
    "minimum-stability": "stable",
    "require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": ">=2.0.5",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*"

    },
    "require-dev": {
        "yiisoft/yii2-codeception": "*", …
Run Code Online (Sandbox Code Playgroud)

composer-php yii2

13
推荐指数
1
解决办法
1万
查看次数

为什么json_encode返回空括号?

$ array的var_dump返回:

array (size=3)
  0 => 
    object(frontend\models\Notifications)[101]
      private '_attributes' (yii\db\BaseActiveRecord) => 
        array (size=5)
          'id' => int 1
          'created_on' => string '2015-11-12 12:12:15' (length=19)
          'user_id' => int 1
          'text' => string '2severity level is 2guardian is 5,Student_id 2 created a Level 2 discipline issue in school' (length=91)
          'is_seen' => int 0
      private '_oldAttributes' (yii\db\BaseActiveRecord) => 
        array (size=5)
          'id' => int 1
          'created_on' => string '2015-11-12 12:12:15' (length=19)
          'user_id' => int 1
          'text' => string '2severity level is 2guardian is 5,Student_id 2 …
Run Code Online (Sandbox Code Playgroud)

php mysql yii

6
推荐指数
1
解决办法
7361
查看次数

barryvdh/laravel-debugbar 没有出现在 laravel 中

请让我断言:这个问题不是这个问题的重复,

在 Laravel 5 中,我尝试安装barryvdh/laravel-debugbar. 但它没有显示。

我做了以下事情:

安装:

composer require barryvdh/laravel-debugbar

将以下行添加到提供程序部分的 config/app.php

'Barryvdh\Debugbar\ServiceProvider',

在外墙列表中..

'Debugbar' => 'Barryvdh\Debugbar\Facade', 我进一步执行:

php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"

之后,我尝试了所有方法来回答我在本问题开头提到的类似问题。

就像在 中启用调试一样.env,在 debugbar.php 中启用它,清除配置缓存php artisan config:clear

并再次缓存

php artisan config:cache

还 .. php artisan view:clear;

但是调试栏不会出现?

可能是什么原因?

php laravel phpdebugbar

5
推荐指数
2
解决办法
1万
查看次数

为什么有些php类有一个空的init()方法?

例如,在Yii2框架中,yii\filters\AccessControl该类init()从其父类重写一个函数yii\base\Object.这个Object类又有一个像这样的构造方法:

    Class Object implements Configurable {
        public function __construct($config = [])
        {
            if (!empty($config)) {
                Yii::configure($this, $config);
        }
        $this->init(); // calls the method defined below
        }
    }
// and the definition of this init function ... 
    public function init()
    {
    }
Run Code Online (Sandbox Code Playgroud)

现在没有明显的使用编写这样一个空函数,除非你想用它来初始化他/她将来可能需要的一些属性.

但是那个__construct()方法的用法完全一样!我需要了解这种init()方法是如何有用的.

php yii2

4
推荐指数
1
解决办法
693
查看次数

在 Laravel 中找不到 ReflectionFunction

要查找在 Laravel 应用程序中定义函数的位置,我正在尝试执行以下操作:

内部App\Http\Controllers命名空间:

$reflFunc = new ReflectionFunction('function_name');
Run Code Online (Sandbox Code Playgroud)

但是得到一个错误:

PHP 错误:在第 169 行的 /var/www/html/s/source/app/Http/Controllers/HomeController.php 中找不到“App\Http\Controllers\ReflectionFunction”类

我什至尝试使用全局命名空间:

ReflectionFunction 类不应该位于 laravel 试图找到它的地方,但是请建议我可能遗漏了什么?

php laravel

4
推荐指数
1
解决办法
669
查看次数

Yii2是否会处理重要的安全问题?

在php中的MySql数据库中存储url时,我不得不使用以下内容, mysql_real_escape_string('xyz/xyz.html') 不推荐使用mysql,现在我使用的是Yii 2.0(作者声称它是安全的).

我使用它的Gii CRUD,现在这个url很容易存储,不需要转义.

(如果它使用PDO,那么准备好的语句可能会解决上述问题)

我想知道Yii-2.0是否会处理与在数据库中存储事物然后将它们分散在视图上相关的重要安全问题.

yii2

3
推荐指数
2
解决办法
493
查看次数

无法解析Firebase崩溃库android'com.google.firebase:firebase-core:11.0.2'

我正在尝试更新我的依赖项以编译'com.google.firebase:firebase-core:11.0.2'但是

我得到的只是:

Failed to resolve: com.google.firebase:firebase-core:11.0.2'
Run Code Online (Sandbox Code Playgroud)

可能是什么原因?

android firebase

3
推荐指数
1
解决办法
2082
查看次数

MySql:错误1018(HY000):无法读取目录'。(错误:13)

最近的MySQL死机了,我只好到备份的内容var/lib/mysql/home/backup/并重新安装数据库。

重新安装mysql服务器后,

  1. 重命名 /var/lib/mysql to mysql.orig

  2. 在/ var / lib中,我做了一个目录mysql

  3. 将内容从home/backup文件夹移动到/ var / lib / mysql

现在通过运行mysql -u user -p并在我调用show databases它时出现以下错误:

MySql:错误1018(HY000):无法读取目录'。(错误:13)

如何解决呢?

php mysql

3
推荐指数
1
解决办法
2351
查看次数

在javascript中创建一个Toggle按钮

我想要一个切换按钮,它的当前css背景颜色值为"红色".在第一次点击它应该变为'黄色',在第二次点击它变为'绿色',在第三次点击它应该变回'红色'.

HTML

<div id="box" class="boxa"> 1 </div>

使用Javascript:

$('div[id="box"]').mousedown(function(){


if($(this).css ('background-color', 'red')) {
       $(this).css ('background-color', 'yellow');    
 }  

});
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为$(this).css ('background-color', 'red')总是返回true,然后尝试将值存储在变量中,然后像这样检查

var color = $(this).css ('background-color');
if (color=="red") {
   // change it to some other color
} 
Run Code Online (Sandbox Code Playgroud)

但这不能作为colorRGB中的返回值.谁能帮我写一个有效的解决方案.

javascript jquery

2
推荐指数
1
解决办法
80
查看次数

为什么这个Javascript承诺不起作用?

我正在学习承诺.

app.get('/message',function(req, res){    
    var promise = new Promise(function(resolve, reject){
        resolve("hi");
    });
    promise.then(function(message){
       res.json(message);
    })

});
Run Code Online (Sandbox Code Playgroud)

这很好用.虽然这太简单了.为了写"冗长"的东西,我把代码移出app.get()并试图从外部函数返回消息......像这样:

    app.get('/message',function(req, res){ 
      var message = message(); // I also tried wrapping this in promise and calling `res.json` in `promise.then()` but no luck
       res.json(message);
    });

    function message(){    
        var promise = new Promise(function(resolve, reject){
            resolve("hi");
        });
        promise.then(function(message){
           return message;
        })

    }
Run Code Online (Sandbox Code Playgroud)

那么为什么函数中的return语句不message()返回消息呢?什么是将这些promising代码移出路线功能的最佳做法?

javascript asynchronous node.js promise

1
推荐指数
1
解决办法
83
查看次数

排序Model.prototype。(customFunction)不起作用

我试图在Sequelize模型中定义一个customFunction 。但是我得到一个错误:

TypeError:user.getJWT不是User.create.then的函数(/projects/test/a/app/controllers/UserController.js:22:29)

这是以下代码models/user.js

module.exports = function(sequelize, Sequelize) {
    var User = sequelize.define('User', {
        id: {
          type: Sequelize.INTEGER(11),
          allowNull: true,
          primaryKey: true,
          autoIncrement: true
        },
        user_id: {
          type: Sequelize.STRING(255),
          allowNull: true,
          defaultValue: ''
        }
      });

      User.prototype.getJWT = function() {
        let expiration_time = parseInt(CONFIG.jwt_expiration);
        return "Bearer " + jwt.sign({
          user_id: this.user_id,
          role: this.role
        }, CONFIG.jwt_encryption, {
          expiresIn: expiration_time
        });
      }
      return User
    }
Run Code Online (Sandbox Code Playgroud)

这就是我在控制器中调用此原型函数的方式...

User.create(body).then((user) => {
      user.token = user.getJWT(); // and here I get the error …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express sequelize.js

1
推荐指数
1
解决办法
2212
查看次数