我在任何地方都做过这种事情,没有遇到任何麻烦,但这次没有成功。
var_dump($fields);
结果:
object(stdClass)[880]
public 'teacher_model' =>
object(BackendClassesFormField)[754]
public 'fieldName' => string 'teacher_model' (length=13)
public 'arrayName' => string 'Shooting' (length=8)
public 'idPrefix' => string 'Form' (length=4)
public 'label' => string 'One model' (length=18)
public 'value' => string '' (length=0)
public 'valueFrom' => string 'teacher_model' (length=13)
public 'defaults' => null
public 'defaultFrom' => null
public 'tab' => string 'some.thing::lang.tab.report' (length=37)
public 'type' => string 'text' (length=4)
public 'options' => null
public 'span' => string 'storm' (length=5)
public 'size' => string 'large' (length=5)
public 'context' => null
public 'required' => boolean false
public 'readOnly' => boolean false
public 'disabled' => boolean false
public 'hidden' => boolean false
public 'stretch' => boolean false
public 'comment' => string '' (length=0)
public 'commentPosition' => string 'below' (length=5)
public 'commentHtml' => boolean false
public 'placeholder' => string '' (length=0)
public 'attributes' => null
public 'cssClass' => string 'col-xs-12 col-md-6 col-lg-4' (length=27)
public 'path' => null
public 'config' =>
array (size=5)
'label' => string 'One model' (length=18)
'span' => string 'storm' (length=5)
'cssClass' => string 'col-xs-12 col-md-6 col-lg-4' (length=27)
'type' => string 'text' (length=4)
'tab' => string 'some.thing::lang.tab.report' (length=37)
public 'dependsOn' => null
public 'trigger' => null
public 'preset' => null
似乎还可以,但现在有人来解释一下吗?
var_dump($fields->teacher_model);
结果:
未定义属性:stdClass::$teacher_model
为什么? ?
所有这些都是通过一个函数执行的。我刚刚发现我的$fields
对象是在被填充之前创建的,我的函数,所以我的var_dump被执行了很多次,即使我只看到最后一次递归,我也可以看到var_dump($fields)的结果,因为之前所有的var_dump递归都不会触发任何错误。对于对象属性可访问性,在Laravel/October CMS中,有时你必须在某些条件下这样做。我把它放在前面,它工作得很好。
if (!isset($fields->teacher_model)) {
return;
}
检查您的php版本是否与octobercms版本兼容