English 中文(简体)
在 CakePhp 中错误导入供应商类
原标题:Error Importing Vendor class in CakePhp
  • 时间:2012-05-26 21:27:33
  •  标签:
  • php
  • cakephp

我有:

App/Vendor/Facebook
App/Vendor/Facebook/facebook.php

在“强”App/主计长/主计长.php

App::uses( facebook ,  Vendor/Facebook );

那么AppCrostser等级是:

class AppController extends Controller {

    public $fb;

    public function beforeFilter() {
        $fb = new Facebook();   
    }   

}

我有一个错误:

Fatal error: Class Facebook not found in /home/users/example.com/www/app/Controller/AppController.php on line 42

这怎么可能?

谢谢!

最佳回答

您必须使用 App::import () 来导入您的文件, 因为它没有遵循 CakePHP 常规 。 以下的片段应该执行此把戏 :

App::import( Vendor ,  Facebook , array( file  =>  Facebook  . DS .  facebook.php ));

另见http://book.cakephp.org/2.0/en/core-ility-librarys/ap.html#loading-vendor-files

问题回答

这件事跟我有关...

我做了一些测试 确实知道发生了什么。

首先,我更名为facebook.php, 改名为facebook.php。 这并非真的必要。 这取决于您的 cakephp 版本 。

因此,在Cake/Core/App.php中,我评论了第738行(返回(bool)包括_on$aped;),并改成需要_onon$aped。

后来,我用LIB CURL出了一个错误, 运行 php facebook lib。 因此, 我安装了它 :

sudo aptitude install php5-curl
sudo /etc/init.d/apache2 restart

这一次, 错误更改为 :

Fatal error: Cannot redeclare class Facebook in (...)

最后,我恢复了Cake/Core/App.php的原件,错误得到解决。

最佳方面





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签