Yii Framework Forum: Mssql Error : The Column Must Be Specified In The Format Of "name:type:label", Where "type" And "label" Are Optional. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Mssql Error : The Column Must Be Specified In The Format Of "name:type:label", Where "type" And "label" Are Optional. I try to get data from old database in mssql server. Rate Topic: -----

#1 User is offline   than_aa 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-November 13

Posted 13 March 2014 - 08:42 PM

Hello,

I want to show data in column name "Search Description" from MSSQL Server.
But column name has a space eg. [No_] ,[Description],[Search Description]

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\.]+)(:(\w*))?(:(.*))?$/',$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.
0

#2 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 508
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 14 March 2014 - 08:02 AM

Can't you rename the column in MSSQL?
José
0

#3 User is offline   than_aa 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-November 13

Posted 14 March 2014 - 08:47 AM

View PostJFReyes, on 14 March 2014 - 08:02 AM, said:

Can't you rename the column in MSSQL?

Databases from other offline applications .
I want create report online for sale team.
0

#4 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 508
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 14 March 2014 - 09:19 AM

With that limitation I don't see an easy way around this unless you use Data Access Objects to bind the column values (see this) or else use straight SQL.

Good luck.
José
0

#5 User is offline   than_aa 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-November 13

Posted 14 March 2014 - 11:37 PM

View Postthan_aa, on 13 March 2014 - 08:42 PM, said:

Hello,

I want to show data in column name "Search Description" from MSSQL Server.
But column name has a space eg. [No_] ,[Description],[Search Description]

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\.]+)(:(\w*))?(:(.*))?$/',$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.



I have the solution for myself.
Just create Views in MSSQL Server and change Alias name as needed.
Attached File  View.png (50.02K)
Number of downloads: 6
Thanks for the suggestion.
0

#6 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 508
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 15 March 2014 - 02:10 AM

Excellent idea! However, take care of a couple of caveats when you use database views in Yii because databases don't expose the following to the schema Yii can access:

1. Primary key - if you need to access the primary key you have to declare it explicitly in the model:
public function primaryKey()
{
    return 'id'; // or whatever the primary key name is
}


2. Updatable view - if you plan on inserting records through the view (must be updatable as per MSSQL requirements (see the remarks section here) its primary key must be retrieved manually in the model:
public function afterSave()
{
    if ($this->getIsNewRecord()) {
       $this->id = Yii::app()->db->getLastInsertID();
    }
    return parent::afterSave();
}


After that, you're all set. Good luck.
José
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users