buggy Posted April 26, 2012 Share Posted April 26, 2012 I'm quite new in PHP and Yii, so any help will be much appreciated. I have table in DB which represents routes, each route, one row. One of attributes is spatial mysql datatype "MULTIPLEPOINT". I would try to keep all points in the same table/row as route itself, rather then creating child table for points. I don't know how to handle it in the Yii Model file. After creating model with the help of gii, 'points' attribute is of course not handled. Should I have child class for points, although I don't have corresponding database table for points, or I should just manually add some array of points in the route class/model ? Table structure is something like this: CREATE TABLE IF NOT EXISTS `Route` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `userId` int(10) unsigned NOT NULL, `routeName` varchar(32) NOT NULL, `routeDescription` varchar(128) NOT NULL, `points` multipoint DEFAULT NULL, PRIMARY KEY (`id`), KEY `userId` (`userId`) ); Link to comment Share on other sites More sharing options...
Edward Posted April 26, 2012 Share Posted April 26, 2012 I tried to setup this in Yii and got the following model code: <?php /** * This is the model class for table "route". * * The followings are the available columns in table 'route': * @property string $id * @property string $userId * @property string $routeName * @property string $routeDescription * @property string $points */ class Route extends CActiveRecord { /** * Returns the static model of the specified AR class. * @param string $className active record class name. * @return Route the static model class */ public static function model($className=__CLASS__) { return parent::model($className); } /** * @return string the associated database table name */ public function tableName() { return 'route'; } /** * @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('userId, routeName, routeDescription', 'required'), array('userId', 'length', 'max'=>10), array('routeName', 'length', 'max'=>32), array('routeDescription', 'length', 'max'=>128), array('points', 'safe'), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('id, userId, routeName, routeDescription, points', '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( ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'ID', 'userId' => 'User', 'routeName' => 'Route Name', 'routeDescription' => 'Route Description', 'points' => 'Points', ); } /** * 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() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria=new CDbCriteria; $criteria->compare('id',$this->id,true); $criteria->compare('userId',$this->userId,true); $criteria->compare('routeName',$this->routeName,true); $criteria->compare('routeDescription',$this->routeDescription,true); $criteria->compare('points',$this->points,true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, )); } } So other than 'safe' Yii didn't have much to say about 'multipoint'? 1 Link to comment Share on other sites More sharing options...
Recommended Posts