0

mssql のテーブルからクラスをモデル化しようとしています。列名にスペースが含まれており、スペースを削除したり、列名を操作したりすることはできません。これを yii に組み込む方法がわかりません。

admin.phpに私が持っている

    <?php 
print_r($model);
$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'components-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'No_',
        'Description',
        "Original Asset Number",
        'Flag',
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

検索.php

<?php
/* @var $this FixedAssetController */
/* @var $model FixedAsset */
/* @var $form CActiveForm */
?>

<div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(
    'action'=>Yii::app()->createUrl($this->route),
    'method'=>'get',
)); ?>

    <div class="row">
        <?php echo $form->label($model,'No_'); ?>
        <?php echo $form->textField($model,'No_'); ?>
    </div>

    <div class="row">
        <?php echo $form->label($model,'description'); ?>
        <?php echo $form->textField($model,'Description',array('size'=>60,'maxlength'=>255)); ?>
    </div>

    <div class="row">
        <?php echo $form->label($model,'Original Asset Number'); ?>
        <?php echo $form->textField($model,"Original Asset Number",array('size'=>60,'maxlength'=>255)); ?>
    </div>


    <div class="row">
        <?php echo $form->label($model,'flag'); ?>
        <?php echo $form->textField($model,'Flag'); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton('Search'); ?>
    </div>

<?php $this->endWidget(); ?>

</div>

私のクラス FixedAsset.php

<?php

/**
 * This is the model class for table "FixedAsset".
 *
 * The followings are the available columns in table 'FixedAsset':
 * @property string $No_
 * @property string $description
 * @property string $original_asset_number
 * @property int    $flag
 *
 */
class FixedAsset extends AltActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Manufacturers the static model class
     */
    public static function model($className=__CLASS__)
    {
        exit(parent::model($className));
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        //exit("help");
        return "[Spectrum Geo Limited\$Fixed Asset]";
    }

    /**
     * @return array validation rules for model attributes.
     */
    /*public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('name', 'required'),
            array('name', 'length', 'max'=>50),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('manufacturer_id, name', 'safe', 'on'=>'search'),
        );
    }*/

    /**
     * @return array relational rules.
     */
    /*public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'components' => array(self::HAS_MANY, 'Components', 'manufacturer'),
        );
    }*/

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        /*return array(
            'manufacturer_id' => 'Manufacturer',
            'name' => 'Name',
        );*/
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        //exit("help");
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('No_',$this->No_);
        $criteria->compare('Original Asset Number',$this->original_asset_number);
        $criteria->compare('Flag',$this->Flag);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}

私のコントローラー

/**
     * Manages all models.
     */
    public function actionAdmin()
    {

        $model=new FixedAsset('search');
        //exit("help2");
        $model->unsetAttributes();  // clear any default values
        if(isset($_GET['FixedAsset']))
            $model->attributes=$_GET['FixedAsset'];

        $this->render('admin',array(
                'model'=>$model,
        ));
    }

    /**
     * Returns the data model based on the primary key given in the GET variable.
     * If the data model is not found, an HTTP exception will be raised.
     * @param integer the ID of the model to be loaded
     */
    public function loadModel($id)
    {
        $model=FixedAsset::model()->findByPk($id);
        if($model===null)
            throw new CHttpException(404,'The requested page does not exist.');
        return $model;
    }

Gii を使用しようとすると、Apache ログにエラーが発生する

[Tue Sep 18 10:51:22 2012] [error] [client 172.16.0.85] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /opt/dam/yii-1.1.12.b600af/framework/db/CDbCommand.php on line 497, referer: http://portal-test/dam/index.php?r=gii/model
4

1 に答える 1

1

列は「名前:タイプ:ラベル」の形式で指定する必要があります。「タイプ」と「ラベル」はオプションです。

スペースがフォーマットを壊しているため、エラーが発生しています。

列に「名前:」を追加するだけです

コードの修正版:

 $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'components-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'Name:No_',
        'Name:Description',
        "Name:Original Asset Number",
        'Name:Flag',
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

これで動作するはずです。

于 2013-08-14T16:39:32.807 に答える