我正在处理我的网站的扩展程序,该扩展程序是此google analytics php class的包装类。 我没有延长任何Yii课程。
我把这个课程放在extensions/GACounter/GACounter.php
class GACounter
{
public $ga_email;
public $ga_password;
public $ga_profile_id;
public function __construct($arr = array())
{
$this->ga_email = Yii::app()->params['ga_email'];
$this->ga_password = Yii::app()->params['ga_password'];
$profileId = Yii::app()->params['ga_profile_id'];
self::setProfile($profileId);
if (!empty($arr)) {
foreach($arr AS $k => $v) {
$this->$k = $v;
}
}
else {
throw new Exception('Array is empty, no settings passed.');
}
}
.....
}
当我在我的视图中调用此类时,就像这样
Yii::import('application.extensions.GACounter.GACounter');
$ga = new ExtGoogleAnalyticsCounter(
array(
'customDateChart' => true,
'startDate' => $startDate,
'endDate' => $endDate,
'dimensions'=> $dimensions,
'metrics'=>urlencode('pageviews'),
'sort_metric'=>$sort_metric,
'filter'=>'pagePath=='.$url,
'start_index'=>1,
'max_results'=>abs($dateRange)
)
);
$totalSiteTraffic = $ga->GetTotalTraffic();
$chartData = $ga->GetChartPerDay();
我收到此错误
Fatal error: Call to undefined method GACounter::init() in /Applications/XAMPP/xamppfiles/htdocs/dev/common/lib/yii/framework/web/CBaseController.php on line 147
只有在我的课程中添加这两个功能时,我才会收到上述错误
public function init() { }
public function run() { }
知道为什么会这样吗?我使用的是Yii 1.1.16