Yii模块仅适用于localhost,但不适用于站点

时间:2014-07-09 02:16:16

标签: php yii-extensions yii yii-components

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

Comments module link

然后我在我的localhost上测试了它并且它有效。但是评论模块在我的网站上不起作用。

以下是我的主要代码:

<?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, ));

它不会显示任何错误,但我的页面将变为白色,我的所有主题都消失了。它只显示了内容而没有评论模块。我认为我的网址管理员有问题。我试图实施以下代码,但仍然没有成功

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

1 个答案:

答案 0 :(得分:0)

我在查看错误日志后设法解决了这个问题。问题是我的网站中的php版本是5.2,而我的localhost是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);