1

所以这里是普通 Yii 控制器中的重要代码。

Yii::import('application.vendors.*');
    require_once('redbean/rb.php');

$config = Yii::app()->getComponents(false);

R::setup($config['db']['connectionString'],
$config['db']['username'],
$config['db']['password'])

$guest = R::dispense( 'guest' );
$guest->email = $row['Guest Email'];

错误发生在dispens() 行。

include(Model_Guestx.php) function.include: 无法打开流: 没有这样的文件或目录 (路径编辑\framework\YiiBase.php:418)

#0路径编辑\framework\YiiBase.php(418): CWebApplication->handleError()

问题是为什么 Yii 试图加载一个与 redbean 同名的模型正在寻找分配?

谢谢!

4

4 回答 4

1

我不知道是什么触发了 Yii 自动加载器,但您可以包含以下代码以使 Yii 跳过 Redbean 创建的任何模型:

public static function autoload($className)
    {
    if(!strncmp("Model_", $className, strlen("Model_")))
        return true;
    //...rest of yii code...

如果将它添加到 YiiBase.php 代码的开头,它将忽略以“Model_”开头的模型,这是 Redbean 使用的。我知道这是一个 hack,但除非您创建打算与 Yii 一起使用的属于该命名类别的模型,否则这应该不是问题。

于 2013-05-03T14:05:03.640 回答
0

如果你想让它更通用,为什么不使用 beforeControllerAction() 和 afterControllerAction() 事件来禁用和启用专用于 redbena 的基本控制器中的 Yii 自动加载,或者如果你想单独使用 redbean。

喜欢:

public function beforeControllerAction(){
spl_autoload_unregister(array('YiiBase','autoload'));   
// other code to execute...
parent::beforeControllerAction(); 
}

    public function afterControllerAction(){
spl_autoload_register(array('YiiBase','autoload'));

// other code to execute...
parent::afterControllerAction();
}
于 2012-06-06T20:12:09.690 回答
0

Yii 有自己的类自动加载器,并且不知何故(可能在检查模型是否存在时)Redbean 创建了一个看起来像 PHP 文件的字符串。所以 Yii 试图包含它。

在使用 Redbean 之前,您可以禁用 yii 自动加载器;然后在完成后重新启用它:

    // Turn off our amazing library autoload 
    spl_autoload_unregister(array('YiiBase','autoload'));   

    Yii::import('application.vendors.*');
    require_once('rb.php');

    R::setup('mysql:host=localhost;dbname=dbname', 'user', 'password');

    $guest = R::dispense('guest');
    $guest->email = $row['Guest Email'];

    // Once we have finished using the library, give back the 
    // power to Yii... 
    spl_autoload_register(array('YiiBase','autoload'));


    $this->render('index');

归功于: http ://www.yiiframework.com/wiki/101/how-to-use-phpexcel-external-library-with-yii/

于 2012-04-04T11:15:46.393 回答
0

如果你想在没有任何选项的情况下使用 Readbean ORM,你可以使用 redbean 查询类型,如

$result = R::$f->begin()->select('*')->from('users')->where(' username = ? ')->put($_xusername)->get('row');

在这里你不需要注册或取消注册自动加载

于 2013-12-04T13:38:58.210 回答