在octobercms中创建前端关系

时间:2016-04-25 10:24:24

标签: php laravel octobercms

我使用hasMany和belongsTo创建了我的模型图像和相册之间的前端关系但是我没有显示任何结果和 {{ dump(images) }}{{ dump(albums) }}提供Object variables NULL 0 NULL

为什么没有接受这种关系的任何想法?

相册

public $hasMany = [
'images' => [ 'Acme\Library\Models\Image' ,'key'=>'album_id'],
];

图像

public $belongsTo = [
'albums' => ['Acme\Library\Models\Album']
];

专辑-details.htm

{{ dump(images) }}
{% for image in images %}
{{image.id|raw }}
{% endfor %}

如果我在{{ dump(record) }}上运行转储,我会

Object variables
Acme\Library\Models\Album
bootValidation()    method  Boot the validation trait for this model. 
forceSave() method  Force save the model even if validation fails.
validate()  method  Validate the model instance
isAttributeRequired()  method  Determines if an attribute is required based      on the validation rules.
errors()    method  Get validation error message collection for the Model
validating()    method  Create a new native event for handling    beforeValidate().
validated() method  Create a new native event for handling afterValidate().
rules   array(0)    
timestamps  boolean 
table   string  
relationConfig  string  
hasMany array(1)

我可以看到使用构建器插件定义了记录{% set records = builderList.records %}

是否需要以这种方式定义专辑/图像?

1 个答案:

答案 0 :(得分:1)

我将记录变量发送到视图,记录是相册的一个实例,您可以通过这种方式访问​​图像。

{% for image in record.images %}
  {{image.id|raw }}
{% endfor %}