dongxi3859 2018-10-23 11:21
浏览 71

想在OctoberCMS中实现SimpleTree

I want to implement parent child relationship in OctoberCMS. I have two model client and session. this is one to many relationship. One client have multiple session. My target is when clicking on a row of client list it will expand the session child row. Here is code of my models -

Client Model

<?php 
namespace Smriad\Pracitioner\Models;

use Model;


class Client extends Model
{
    use \October\Rain\Database\Traits\Validation;
    use \October\Rain\Database\Traits\SimpleTree;


    public $timestamps = false;

    /**
     * @var array Validation rules
     */
    public $rules = [
    ];

    /**
     * @var string The database table used by the model.
     */
    public $table = 'smriad_pracitioner_client';

    public $hasMany = [
        'session' => ['Smriad\Pracitioner\Models\Session', 'key' => 'client_id']
        // ^ you can use house instead houses for relation name
    ];
}

Session Model

<?php namespace Smriad\Pracitioner\Models;

use Model;

/**
 * Model
 */
class Session extends Model
{
    use \October\Rain\Database\Traits\Validation;

    use \October\Rain\Database\Traits\SimpleTree;
    /*
     * Disable timestamps by default.
     * Remove this line if timestamps are defined in the database table.
     */
    public $timestamps = false;

    /**
     * @var array Validation rules
     */
    public $rules = [
    ];

    /**
     * @var string The database table used by the model.
     */
    public $table = 'smriad_pracitioner_client_session';

    public $belongsTo = [
        'client' => ['Smriad\Pracitioner\Models\Client', 'key' => 'client_id']
        // ^ you can use house instead houses for relation name
    ];
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求学软件的前人们指明方向🥺
    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
    • ¥15 MCNP里如何定义多个源?
    • ¥20 双层网络上信息-疾病传播
    • ¥50 paddlepaddle pinn
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services