"#" in table field name - ( ERROR : Attribute name must contain word characters only.)

Hello All,

I am using Yii 2.0, Getting "Attribute name must contain word characters only" error.

I know it is bad practice to use "#" in table field name, But i have no option because i am converting old project in Yii 2.0 and client doesnot want me to make change in DB.

I Fixed this issue for listing and in relation by wrapping field name by curly braces "{}"


I made changes in <Model>Search.php, Befor the statement was

$query->andFilterWhere([‘like’, ‘com#id’, $this->com#id]); which was commenting everything after “#” then i changed it to $query->andFilterWhere([‘like’, ‘com#id’, $this->{‘com#id’}]);, Which is working for me.

but when i try to access update view it is giving me problem, “Attribute name must contain word characters only” after tracing a bit i got to see that in “BaseHtml” class we have “if (preg_match(’/(^|.\])([\w\.]+)(\[.|$)/’, $attribute, $matches))” which is cousing this error.

I can change this condition and write new which can accept "#" in field name but i dnt thing that is recomonded, Can anyone help me to solve this issue.


Thank you in advance.

:blink: That sucks. I feel genuinely sorry for you. Perhaps you can open a ticket?

In the meantime, implementing your own BaseHtml helper is your best way out.