在Gridview函数yii2中访问变量(Access variable in Gridview function yii2)
我想访问一个变量的视图文件到
Gridview
但它抛出的错误,it should be array but null given
我宣布$totalDays
在我的视图文件的顶部,我在下面的$totalDays
使用它[ 'attribute' => 'class_id', 'format' => 'raw', 'label' => "Class Date", 'value' => function ($model) { array_push($totalDays,$model->class->date); return $model->class->date; }, 'footer'=> '<span>Total Days</span>', ],
但它会抛出以下错误
array_push()期望参数1是数组,给出null
I am trying to access a variable on view file into
Gridview
but it is throwing error thatit should be array but null given
i am declaring$totalDays
on top of my view file and i am using it inGridview
like below[ 'attribute' => 'class_id', 'format' => 'raw', 'label' => "Class Date", 'value' => function ($model) { array_push($totalDays,$model->class->date); return $model->class->date; }, 'footer'=> '<span>Total Days</span>', ],
But it throws following error
array_push() expects parameter 1 to be array, null given
原文:https://stackoverflow.com/questions/34444766
最满意答案
这不是什么。 “完成”不会终止bash中的“if”条件。 您应该删除“完成”并在else主体的末尾添加“fi”。
另外,不需要“退出1”之后的分号。
That's not bash. "done" does not terminate an "if" condition in bash. You should remove "done" and add "fi" at the end of the else body.
Also, the semicolon after "exit 1" is not needed.
相关问答
更多-
它可能是TITLE= "$1"中导致错误的空间。 尝试使用TITLE="$1" It may be the space in TITLE= "$1" that causes the error. Try with TITLE="$1"
-
解决方案1 : 由于某种原因, virtualenvwrapper.sh安装在/usr/bin/virtualenvwrapper.sh ,而不是/usr/local/bin 。 我的.bash_profile的以下内容可以正常工作 source "/usr/bin/virtualenvwrapper.sh" export WORKON_HOME="/opt/virtual_env/" 我的安装似乎工作正常,没有来源virtualenvwrapper_bashrc 解决方案2 : 或者如下所述,如果你特别 ...
-
在[赋值之后=之前或之后没有空格]之后需要一个空格。 $(($i+1)))会尝试执行((...))表达式的输出,我确信这不是你想要的。 此外,您在数组名称前缺少$ 。 通过更正这些内容,您的while循环将是: #!/bin/bash i=0 while [ "$i" -le "${#myarray[@]}" ] do echo "Welcome $i times" i=$((i + 1)) done i=$((i + 1))也可以写成((i++)) 将变量括在[ ... ]内的双引号中总是更好 ...
-
未找到bash输出命令(bash output command not found)[2024-01-04]
这不是什么。 “完成”不会终止bash中的“if”条件。 您应该删除“完成”并在else主体的末尾添加“fi”。 另外,不需要“退出1”之后的分号。 That's not bash. "done" does not terminate an "if" condition in bash. You should remove "done" and add "fi" at the end of the else body. Also, the semicolon after "exit 1" is not ne ... -
未找到BASH命令(BASH Command Not Found)[2024-05-13]
bug的解释 某些版本/ wc实现使得格式化输出并在您尝试的值之前放置空格: $ wc -l < <(find /sys/block/ -name 'sd*') 3 请注意, wc输出包含空格。 现在尝试: $ findhdds= 3 bash: 3: command not found 获取SO问题中报告的错误。 两种解决方案(以及更多......): .1计算答案以确保它成为一个数字: findhdds=$((0+$(find /sys/block/ -name 'sd*' | wc -l))) ... -
从外部源的Bash加载函数生成命令未找到[关闭](Bash loading function from external source produces command not found [closed])[2022-05-27]
有一个错字。 trim_quoteS是函数的正确名称。 #!/bin/bash source script2.sh X=$(trim_quotes "\"hello\"") echo $X 跑: $ ./script1.sh hello There's a typo. trim_quoteS is the correct name of function. #!/bin/bash source script2.sh X=$(trim_quotes "\"hello\"") echo $X R ... -
顺便说一下,你的脚本运行正常。 在上传到UNIX环境之前,您是否有机会在Windows环境中键入它? 试试跑步: dos2unix script.sh 这样做是将行结尾从Windows更改为unix格式。 即它从行结尾剥离\ r(CR)以将它们从\ r \ n(CR + LF)更改为\ n(LF)。 此外,在HTML备注上,您在标题标记后缺少“”的结束标记。 BTW, your script works fine. Did you by any chance type it up in a W ...
-
你的PATH看起来很合理。 PATH问题是这种错误的常见原因,但不是唯一的问题。 错误消息“:没有这样的文件或目录”表明脚本文件具有DOS / Windows样式的行结尾(由回车后跟换行组成)而不是unix样式(只是换行)。 Unix程序(包括shell)倾向于将回车误认为部分线路,导致大量混乱。 在这个例子中,它将shebang行视为“#!/ bin / bash ^ M”(其中“^ M”表示回车),去寻找名为“/ bin / bash ^ M”的解释器,不能找到它,打印出类似“/ bin / bash ...
-
指定应运行脚本的应用程序时,只能使用应用程序可以理解的脚本语言。 显然,Expect不是bash,并且不理解bash命令。 我建议你分开这两个脚本。 编写第一部分!#/bin/bash ,第二部分用于Expect。 使第一个脚本调用第二个脚本并将其重定向到chntpw。 When you specify the application that should run your script, you can only use the scripting language that application w ...
-
看起来您从网站或其他来源复制了一行。 通常,终端命令以文档中的示例终端提示为前缀。 例如,如果您被指示运行ls命令,则通常会将其打印为 $ ls 在文档中。 $ 不是命令的一部分,它只代表一个终端提示符。 所以在没有$情况下运行brew install pyqt 。 It looks like you copied a line from a website or other source. Generally, terminal commands are prefixed by a sample ter ...