在 Yii 框架中使用 Zend Gdata

发布于 2024-12-06 02:38:13 字数 1226 浏览 2 评论 0原文

我正在尝试从 Zend Gdata 的 Picasa 获取一些照片。这是我的代码:

public function getAlbumFeed($albumName){
    require_once('Zend/Loader.php');
    spl_autoload_unregister(array('YiiBase','autoload'));
    spl_autoload_register(array('Zend_Loader_Autoloader','autoload'));
    spl_autoload_register(array('YiiBase','autoload'));
    Zend_Loader::loadClass('Zend_Gdata');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    Zend_Loader::loadClass('Zend_Gdata_Photos');
    Zend_Loader::loadClass('Zend_Http_Client');

    $svc=Zend_Gdata_Photos::AUTH_SERVICE_NAME;
    $client=Zend_Gdata_ClientLogin::getHttpClient($this->email, $this->password, $svc);
    $gphoto=new Zend_Gdata_Photos($client);

    $query=$gphoto->newAlbumQuery();
    $query->setUser('default');
    $query->setAlbumName($albumName);

    try{
        $feed=$gphoto->getAlbumFeed($query);
    }
    catch(Zend_Gdata_App_Exception $e){
        throw new HttpException("Your photos can't find", 404);
    }
    return $feed;
}

但是当我运行这个脚本时,我的网站抛出一个错误:

Fatal error: Class 'CExceptionEvent' not found in D:\xampp\htdocs\yii\framework\base\CApplication.php on line 703

你能帮我解决这个问题吗?非常感谢。

I am trying to fetch some photos from Picasa by Zend Gdata. This is my code:

public function getAlbumFeed($albumName){
    require_once('Zend/Loader.php');
    spl_autoload_unregister(array('YiiBase','autoload'));
    spl_autoload_register(array('Zend_Loader_Autoloader','autoload'));
    spl_autoload_register(array('YiiBase','autoload'));
    Zend_Loader::loadClass('Zend_Gdata');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    Zend_Loader::loadClass('Zend_Gdata_Photos');
    Zend_Loader::loadClass('Zend_Http_Client');

    $svc=Zend_Gdata_Photos::AUTH_SERVICE_NAME;
    $client=Zend_Gdata_ClientLogin::getHttpClient($this->email, $this->password, $svc);
    $gphoto=new Zend_Gdata_Photos($client);

    $query=$gphoto->newAlbumQuery();
    $query->setUser('default');
    $query->setAlbumName($albumName);

    try{
        $feed=$gphoto->getAlbumFeed($query);
    }
    catch(Zend_Gdata_App_Exception $e){
        throw new HttpException("Your photos can't find", 404);
    }
    return $feed;
}

But when I run this script, my website throw a error:

Fatal error: Class 'CExceptionEvent' not found in D:\xampp\htdocs\yii\framework\base\CApplication.php on line 703

Could you help me to solve this problem? Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋檐 2024-12-13 02:38:13

问题的原因是您抛出了一个异常(可能是代码末尾附近的 HttpException),并且 Yii 想要构造一个 CExceptionEvent 实例,以便它可以引发 CApplication::onException 事件。

然而,Yii 的类自动加载器已从自动加载堆栈中删除,因此 PHP 无法找到该类。

尝试注释掉删除和添加 Yii 自动加载器的代码,看看是否有区别:

// spl_autoload_unregister(array('YiiBase','autoload'));
spl_autoload_register(array('Zend_Loader_Autoloader','autoload'));
// spl_autoload_register(array('YiiBase','autoload'));

您还可以调用 spl_autoload_functions 来检查你的 spl_autoload 堆栈到底发生了什么——也许有什么东西损坏了它:

print_r(spl_autoload_functions());
die;  // see what the line above prints

$svc=Zend_Gdata_Photos::AUTH_SERVICE_NAME;

The cause of the problem is that you are getting an exception thrown (probably that HttpException near the end of your code), and Yii wants to construct a CExceptionEvent instance so that it can raise the CApplication::onException event.

However, Yii's class autoloader has been removed from the autoload stack and as a result PHP cannot find the class.

Try commenting out the code that removes and adds Yii's autoloader and see if it makes a difference:

// spl_autoload_unregister(array('YiiBase','autoload'));
spl_autoload_register(array('Zend_Loader_Autoloader','autoload'));
// spl_autoload_register(array('YiiBase','autoload'));

You can also call spl_autoload_functions to check what exactly is going on with your spl_autoload stack -- maybe something has corrupted it:

print_r(spl_autoload_functions());
die;  // see what the line above prints

$svc=Zend_Gdata_Photos::AUTH_SERVICE_NAME;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文