在yii2中Gii生成的搜索模型中的语法错误(Syntax error in Gii generated Search Model in yii2)

编程入门 行业动态 更新时间:2024-10-23 11:16:43
在yii2中Gii生成的搜索模型中的语法错误(Syntax error in Gii generated Search Model in yii2)

我使用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

更多推荐

本文发布于:2023-08-07 20:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465548.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模型   语法错误   Gii   Syntax   Search

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!