Yii模块仅适用于本地主机,但不适用于网站


Yii module only works on localhost but not on sites

我有一个网站,我使用Yii引导框架开发它。然后我只想创建一个评论模块,我从Yii下载了这个模块(链接如下):

注释模块链接

然后我在我的本地主机上测试了它,它工作了。然而,评论模块不工作在我的网站。

下面是main的代码:
<?php
require_once( dirname(__FILE__) . '/../components/Helper.php');
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
Yii::setPathOfAlias('CoverUploadDir', dirname(__FILE__).'/../../uploads/covers');
Yii::setPathOfAlias('ContentsUploadDir', dirname(__FILE__).'/../../uploads/contents');
error_reporting(E_ALL ^ E_NOTICE);
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'Smart Mobile Library',
'theme' => 'bootstrap',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
    'application.models.*',
    'application.components.*',

),
'modules'=> array( 

'comments'=>array(
        //you may override default config for all connecting models
    'defaultModelConfig' => array(
        //only registered users can post comments
    'registeredOnly' => true,
    'useCaptcha' => true,
        //allow comment tree
    'allowSubcommenting' => true,
        //display comments after moderation
    'premoderate' => false,
        //action for posting comment
    'postCommentAction' => 'comments/comment/postComment',
        //super user condition(display comment list in admin view and automoderate comments)
    'isSuperuser'=>'Yii::app()->user->isAdmin()',
     //order direction for comments
    'orderComments'=>'DESC',
    ),
    //the models for commenting
    'commentableModels'=>array(
        //model with individual settings
        'Book'=>array(
            'registeredOnly'=>true,
            'useCaptcha'=>true,
            'allowSubcommenting'=>false,
            //config for create link to view model page(page with comments)
            'pageUrl'=>array(
                'route'=>'/admin/book',
                'data'=>array('id'=>'book_id'),
            ),
        ),
        //model with default settings
    'ImpressionSet',
    ),
    //config for user models, which is used in application
    'userConfig'=>array(
        'class'=>'User',
        'nameProperty'=>'fullname',
        'emailProperty'=>'email',
    ),
),

    'gii'=>array(
        'class'=>'system.gii.GiiModule',
        'password'=>'lovesick',
        'ipFilters'=>array('127.0.0.1','::1'),
        'generatorPaths'=>array(
            'bootstrap.gii',
        ),
    ),

),
// application components
'components'=>array(
    'counter' => array(
         'class' => 'bootstrap.components.UserCounter',
                    ),
    'bootstrap'=>array(
        'class'=>'bootstrap.components.Bootstrap',
    ),
    'user'=>array(
        'allowAutoLogin'=>true,
        'class' => 'Admin',
    ),
    // uncomment the following to enable URLs in path-format
    /*
    'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
            '<controller:'w+>/<id:'d+>'=>'<controller>/view',
            '<controller:'w+>/<action:'w+>/<id:'d+>'=>'<controller>/<action>',
            '<controller:'w+>/<action:'w+>'=>'<controller>/<action>',

        ),
    ),
    */
    'db'=>array(
        'connectionString' => 'mysql:host=127.0.0.1;dbname=smartmob_administrators',
        'emulatePrepare' => true,
        'username' => 'donkey',
        'password' => 'donkey1001',
        'charset' => 'utf8',
        'tablePrefix' => 'tbl_',
    ),
    'errorHandler'=>array(
        // use 'site/error' action to display errors
        'errorAction'=>'site/error',
    ),
    'log'=>array(
        'class'=>'CLogRouter',
        'routes'=>array(
            array(
                'class'=>'CFileLogRoute',
                'levels'=>'error, warning',
            ),
            // uncomment the following to show log messages on web pages
            /*
            array(
                'class'=>'CWebLogRoute',
            ),
            */
        ),
    ),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
    // this is used in contact page
    'adminEmail'=>'admin@smartmobilelibrary.com',
  ),
);
我已经遵循了所有的指导方针,但我真的不知道是什么问题。当我调用 下面的别名时
 $this->widget('comments.widgets.ECommentsListWidget', array(     'model' => $model, ));

它不会显示任何错误,但是我的页面会变成白色,所有的主题都不见了。它只显示内容,不显示注释模块。我认为我的url管理器有问题。我已经尝试实现以下代码,但仍然没有成功

'<modules:'w+>/<controller:'w+>/<action:['w-]+>' => '<modules>/<controller>/<action>',
'<modules:'w+>/<controller:'w+>'                 =>        '<modules>/<controller>',
'<modules:'w+>'                                  => '<modules>',

查看错误日志后,我已经设法解决了这个问题。问题是php版本在我的网站是5.2和在我的本地主机是5.3。因此它给我的错误是

syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

这个错误是由于public function getOwnerModel()在注释模型中额外的双冒号而发生的,其中错误在337行,如下所示:基本上,下面的代码只适用于php 5.3,而不适用于php5.2

$this->_ownerModel = $ownerModel::model()->findByPk($key);

所以我把它改成:

$model = call_user_func(array($ownerModel, 'model'));
$this->_ownerModel =  $model->findByPk($key);
相关文章: