Hello,
learning Yii2 I encountered the following problem:
I wanted to use Gii to set up all necessary files for handling with my table ‘mytable’.
Using the Model-generator was successful. Using the CRUD-Generator resulted in an error rigth after clicking ‘Preview’:
syntax error, unexpected '-', expecting '('
The Error was found in ‘models\Mytable’ at line 114, which reads
public function getSN-Unit()
The corresponding tablefield in the Database reads ‘SN-Unit’.
The table ‘mytable’ relates to the table ‘subnational_units’ and the field ‘SN-Unit’ corresponds to the field ‘ISO3166-2’ in the table ‘subnational_units’. The above mentioned function that threw the error says
public function getSN-Unit()
{
return $this->hasOne(SubnationalUnits::className(), ['ISO3166-2' => 'SN-Unit']);
}
which, as far as I understood, tries to set up relational rules for the ActiveRecord. It seems Gii has a problem with table and field-names not follwing a specific naming-convention, specifically if a ‘-’ is used, is that right?
Do I have to rename all fields with ‘-’?
hbergman