微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – T_PAAMAYIM_NEKUDOTAYIM覆盖CButtonColumn后出错

我重写CButtonColumn类和代码在localhost(windows)上完美地工作,但是当我将它上传linux服务器时,我遇到了这个错误

Parse error: Syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /home/xxx/public_html/protected/components/GridView/XCButtonColumn.PHP on line 65

我读到了什么意思是“T_PAAMAYIM_NEKUDOTAYIM”,它的意思是“::”
link here
,但我不明白我能做些什么来解决问题.

第65行:

if (is_array($modelClass::model()->primaryKey))

这是我的代码

<?PHP
class XCButtonColumn extends CButtonColumn
{
    public $htmlOptions = array('class' => 'center vcenter');
    public $viewButtonoptions = array('class' => 'btn btn-default tip view');
    public $viewButtonImageUrl = '';
    public $viewButtonHtml;
    public $updateButtonoptions = array('class' => 'btn btn-default tip update');
    public $updateButtonImageUrl = '';
    public $updateButtonHtml;
    public $deleteButtonoptions = array('class' => 'btn btn-default tip delete');
    public $deleteButtonImageUrl = '';
    public $deleteButtonHtml;
    public $showImage = false;
    public $showHtml = true;

    protected function renderButton($id, $button, $row, $data)
    {
        if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row' => $row, 'data' => $data))) return;
        $label = isset($button['label']) ? $button['label'] : $id;
        $url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data' => $data, 'row' => $row)) : '#';
        $options = isset($button['options']) ? $button['options'] : array();
        if (!isset($options['title'])) $options['title'] = $label;
        if ($this->showImage) {
            if (isset($button['imageUrl']) && is_string($button['imageUrl'])) {
                echo CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options);
            } else {
                echo CHtml::link($label, $url, $options);
            }
        } else {
            if (isset($button['html']) && is_string($button['html'])) {
                echo CHtml::link($button['html'], $url, $options);
            } else {
                echo CHtml::link($button['html'], $url, $options);
            }
        }
    }

    protected function initDefaultButtons()
    {
        if ($this->viewButtonLabel === null) $this->viewButtonLabel = Yii::t('zii', 'View');
        if ($this->updateButtonLabel === null)
            $this->updateButtonLabel = Yii::t('zii', 'Update');
        if ($this->deleteButtonLabel === null)
            $this->deleteButtonLabel = Yii::t('zii', 'Delete');
        if ($this->viewButtonImageUrl === null)
            $this->viewButtonImageUrl = $this->grid->baseScriptUrl .
                '/view.png';
        if ($this->updateButtonImageUrl === null)
            $this->updateButtonImageUrl = $this->grid->baseScriptUrl
                . '/update.png';
        if ($this->deleteButtonImageUrl === null)
            $this->deleteButtonImageUrl = $this->grid->baseScriptUrl
                . '/delete.png';
        if ($this->viewButtonHtml === null)
            $this->viewButtonHtml = '<i class="icon-zoom-in iconwhite"></i>';
        if ($this->updateButtonHtml === null)
            $this->updateButtonHtml = '<i class="icon-edit iconwhite"></i>';
        if ($this->deleteButtonHtml === null)
            $this->deleteButtonHtml = '<i class="icon-trash iconwhite"></i>';
        if ($this->deleteConfirmation === null)
            $this->deleteConfirmation = Yii::t('zii', 'Are you sure you want to delete this item?');
        $modelClass = $this->grid->dataProvider->modelClass;
        $controller = strtolower($modelClass);
        if (is_array($modelClass::model()->primaryKey))
            $paramExpression = '",$data->primaryKey)';
        else
            $paramExpression = '",array("id"=>$data->primaryKey))';
        foreach (array('view', 'update', 'delete') as $id) {
            $button = array(
                'label' => $this->{$id . 'ButtonLabel'},
                'url' => 'Yii::app()->urlManager->createUrl("' . "$controller/$id$paramExpression",
                'imageUrl' => $this->{$id . 'ButtonImageUrl'},
                'html' => $this->{$id . 'ButtonHtml'},
                'options' => $this->{$id . 'Buttonoptions'},
            );
            if (isset($this->buttons[$id]))
                $this->buttons[$id] = array_merge($button, $this->buttons[$id]);
            else
                $this->buttons[$id] = $button;
        }
        if (!isset($this->buttons['delete']['click'])) {
            if (is_string($this->deleteConfirmation))
                $confirmation = "if(!confirm(" .
                    CJavaScript::encode($this->deleteConfirmation) . ")) return false;";
            else
                $confirmation = '';
            if (Yii::app()->request->enableCsrfValidation) {
                $csrftokenName = Yii::app()->request->csrftokenName;
                $csrftoken = Yii::app()->request->csrftoken;
                $csrf = "\n\t\tdata:{ '$csrftokenName':'$csrftoken'
},";
            } else
                $csrf = '';
            if ($this->afterDelete === null)
                $this->afterDelete = 'function(){}';
            $this->buttons['delete']['click'] = <<<EOD
function() {
$confirmation
var th = this,
afterDelete = $this->afterDelete;
jQuery('#{$this->grid->id}').yiiGridView('update', {
type: 'POST',
url: jQuery(this).attr('href'),$csrf
success: function(data) {
jQuery('#{$this->grid->id}').yiiGridView('update');
afterDelete(th, true, data);
},
error: function(XHR) {
return afterDelete(th, false, XHR);
}
});
return false;
}
EOD;
        }
    }
}

提前致谢

解决方法:

首先感谢benka的帮助,问题是在PHP版本和PHP 5.2不支持
这一行:

if (is_array($modelClass::model()->primaryKey))

所以要在PHP 5.2上工作,我改为:

if (is_array(CActiveRecord::model($modelClass)->primaryKey))

参考文献:

Link 1

Link 2

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐