Yii – “Model.id” not defined - CGridView one to many relation

März 29th, 2012

Link: http://harrybailey.com/2011/07/yii-model-id-not-defined-for-carraydataprovider-and-csqldataprovider-etc/

I found my solution under the link from Harry

$config = array('keyField' => 'idheatflow');
$dataProvider = new CArrayDataProvider($rawData=$model->heatflows, $config);

Creation in giix step by step

March 25th, 2012

for all tables the following:

  1. Module Generator
  2. Model Generator
  3. CRUD Generator
Is essential in config/main.php to add the modules in modules array. If not, giix CRUD Generator write the files not in the correct module folder. Dont forget to autoload all the relation models!!

Fundamentals in Yii: Namespaces and Path Alias

March 25th, 2012

Link: http://www.yiiframework.com/doc/guide/1.1/en/basics.namespace

Path for a giix code in crud generator:
Model Class
application.modules.heatflow.models.Heatflow
Controller ID
heatflow/Heatflow


Meanwhile another error message is coming:
Table 'heatflow' has a composite primary key which is not supported by crud generator.
I have a try to giix Extension. I am lazy and think is better to install extensions for better building the code.

    public function validateModel($attribute,$params)
    {
        if($this->hasErrors('model'))
            return;
        $class=@Yii::import($this->model,true);
        if(!is_string($class) || !$this->classExists($class))
            $this->addError('model', "Class '{$this->model}' does not exist or has syntax error.");
        else if(!is_subclass_of($class,'CActiveRecord'))
            $this->addError('model', "'{$this->model}' must extend from CActiveRecord.");
        else
        {
            $table=CActiveRecord::model($class)->tableSchema;
            if($table->primaryKey===null)
                $this->addError('model',"Table '{$table->name}' does not have a primary key.");
            else if(is_array($table->primaryKey))
                $this->addError('model',"Table '{$table->name}' has a composite primary key which is not supported by crud generator.");
            else
            {
                $this->_modelClass=$class;
                $this->_table=$table;
            }
        }
    }

Solution will be a workaround to that composite primary key. Using only one primary key. Other keys can not be  primary.