我使用Gii工具生成了一个名为vast_table的表的搜索模型。 但是我在Gii生成的模型中有一个语法错误,这是完全正常的。 错误是:
PHP Parse Error – yii\base\ErrorException syntax error, unexpected ']'我的搜索模型如下所示:
$query->andFilterWhere(['like', 'Ad', $this->Ad]) ->andFilterWhere(['like', 'Collapse', $this->Collapse]) ->andFilterWhere(['like', 'CloseLinear', $this->CloseLinear]) ->andFilterWhere(['like', 'Skip', $this->Skip]) ->andFilterWhere(['like', 'Played10%', $this->Played10%]) ->andFilterWhere(['like', 'Played30%', $this->Played30%]) ->andFilterWhere(['like', 'Played40%', $this->Played40%]) ->andFilterWhere(['like', 'Played60%', $this->Played60%]);错误指向最后四行。 我该怎么办请帮忙。
I have generated a search model for a table called vast_table using Gii tool. However I have a syntax error in the Gii generated model which is perfectly fine. The error is :
PHP Parse Error – yii\base\ErrorException syntax error, unexpected ']'My search model looks like this :
$query->andFilterWhere(['like', 'Ad', $this->Ad]) ->andFilterWhere(['like', 'Collapse', $this->Collapse]) ->andFilterWhere(['like', 'CloseLinear', $this->CloseLinear]) ->andFilterWhere(['like', 'Skip', $this->Skip]) ->andFilterWhere(['like', 'Played10%', $this->Played10%]) ->andFilterWhere(['like', 'Played30%', $this->Played30%]) ->andFilterWhere(['like', 'Played40%', $this->Played40%]) ->andFilterWhere(['like', 'Played60%', $this->Played60%]);The error is pointing to the last four lines. What should I do please help.
最满意答案
百分号'%'是php中的模运算符
虽然您可以将db列定义为Played60% ,但php不允许您将特殊字符放在变量名中
您可以将这些列重命名为Played60p也可以手动调整由gii生成的模型属性,使其在语法上正确。
另外这里是yii提供的架构设计指南
the percent sign '%' is the modulo operator in php
while you may be able to define a db column as Played60%, php wont allow you to put special characters in variable names
you may either rename those columns to something like Played60p or manually adjust the model properties that have been generated by gii to be syntactically correct.
additionally here's the schema design guideline yii provides
更多推荐
发布评论