0
0

More than 3 years have passed since last update.

OctoberCMS viewの表示

Posted at

モデルの中身が以下のようなとき、

models>User.php

public $belongsTo = [
  'divgroup' => [
    '<プロジェクト名>\<プラグイン名>\Models\<モデル名>',
    'table' => '<>',
    'order => 'div_name' <!-- いるのかわかってない -->
  ]
];

<!-- 下はRainLabのUserプラグイン規定値 -->
public $belongsToMany = [
  'groups' => [
    UserGroup::class,
    'table' => 'user_groups'
  ]
];

viewでは以下のように記述する


<!-- divgroupの表示 -->
{{ user.divgroup.div_name }} <!-- divgroupのdiv_nameカラムをとってくる

<!-- groupsの表示 -->
{% for group in user.groups %}
  {{ group.name }} <!-- groupのnameカラムをとってくる -->
{% endfor %}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0