4

I overrode CButtonColumn class and code worked in perfect way on localhost(windows) , but when I uploaded it to linux server I had this error :

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

I read about what mean "T_PAAMAYIM_NEKUDOTAYIM" , it's mean "::" link here ,but I didn't understood what i can do to fix problem .

line 65:

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

This is my code :

<?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;
        }
    }
}

Thanks in advance

Community
  • 1
  • 1
Ahmad Samilo
  • 914
  • 16
  • 30

2 Answers2

4

First thanks to benka to help , the problem is in php version and php 5.2 not support this line :

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

So to be work on php 5.2 I changed it to be :

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

References :

Link 1

Link 2

Community
  • 1
  • 1
Ahmad Samilo
  • 914
  • 16
  • 30
-1

should be -> instead of ::

if (is_array($modelClass->model()->primaryKey))
benka
  • 4,732
  • 35
  • 47
  • 58
  • I traid it before but not worked : Fatal error: Call to a member function model() on a non-object in /home/xxx/public_html/protected/components/GridView/XCButtonColumn.php on line 65 – Ahmad Samilo Nov 16 '13 at 13:52
  • 2
    @AhmadSamilo have you checked this thread: http://stackoverflow.com/questions/3787957/cant-call-static-method-from-class-as-variable-name – benka Nov 16 '13 at 13:56
  • I guess I understood the problem , i check my php version on linux 5.2 and on windows 5.3 , but how to fix it I will try to upgrade php. thank you – Ahmad Samilo Nov 16 '13 at 14:09
  • 1
    `model` *function* is **static** it should not be called with `->` –  Oct 15 '14 at 11:43