Hello,
I want to show data in column name "[color="#00FFFF"]Search Description[/color]" from MSSQL Server.
But column name has a space eg. [No_] ,[Description],[[color="#00FFFF"]Search Description[/color]]
System Show ERROR.
The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.
C:\inetpub\framework\zii\widgets\grid\CGridView.php(412)
400 foreach($this->columns as $column)
401 $column->init();
402 }
403
404 /**
405 * Creates a {@link CDataColumn} based on a shortcut column specification string.
406 * @param string $text the column specification string
407 * @return CDataColumn the column instance
408 */
409 protected function createDataColumn($text)
410 {
411 if(!preg_match('/^([\w\.]+)(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />\w*))?(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />.*))?$/',$text,$matches))
412 throw new CException(Yii::t('zii','The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.'));
413 $column=new CDataColumn($this);
414 $column->name=$matches[1];
415 if(isset($matches[3]) && $matches[3]!=='')
416 $column->type=$matches[3];
417 if(isset($matches[5]))
418 $column->header=$matches[5];
419 return $column;
420 }
421
422 /**
423 * Registers necessary client scripts.
424 */
My View
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $Items->search(),
'filter' => $Items,
'columns' => array(
'No_',
'Description',
'Search Description', // Error if enable;
),
));
My Model
class Items extends CActiveRecord {
public static function model($className = __CLASS__) {
return parent::model($className);
}
public function tableName() {
return "[DB_TH\$Item]";
}
public function attributeLabels(){
return array(
"[No_]" => "Items",
"[Description]" => "Description",
"[Search Description]" => "Search Description"
);
}
public function search() {
$criteria = new CDbCriteria;
$criteria->compare("[No_]", $this->No_, true);
$criteria->compare("[Description]", $this->Description, true);
//$criteria->compare("[Search Description]", $this->Search Description, true); // Error if enable;
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
"pagination" => array(
"pageSize" => 30
)
));
}
public function rules(){
return array(
array('No_,Description','required'),
array('No_,Description', 'safe' ,'on' => 'search'),
);
}
}
My Controller
public function actionShowItems()
{
$Item = new Items();
$Item->unsetAttributes();
if(isset($_GET['Items'])){
$Item->attributes = $_GET['Items'];
}
$this->render("Items", array("Items" => $Item));
}
*** If I do not put "Search Description" can run normally.
Help me please.