首页 \ 问答 \ 在Gridview函数yii2中访问变量(Access variable in Gridview function yii2)

在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 that it should be array but null given i am declaring $totalDays on top of my view file and i am using it in Gridview 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
更新时间:2021-11-28 13:11

最满意答案

这不是什么。 “完成”不会终止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中的“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 ...
  • 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))) ...
  • 有一个错字。 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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。