十月CMS |如何从特定页面上安装的组件中获取属性值?

问题描述 投票:1回答:2

我使用“每页”选项创建了我的组件,接受一个数字并设置每页工作显示器的限制...

enter image description here

public function defineProperties()
    {
        return [
            'perPage' => [
                'title' => 'Number os works per page',
                'description' => 'How many works do you want to display per page?',
                'default' => 9,
                'validationPattern' => '^[0-9]+$',
                'validationMessage' => 'Only numbers allowed'
            ],
            'sortOrder' => [
                'title' => 'Order of Works',
                'description' => 'How do you want to order the actors',
                'type' => 'dropdown',
                'default' => 'newest',
            ],
        ];
    }

它在GET实现方面很有用......但是在我的项目中我需要在任何地方实现AJAX,所以我需要通过AJAX加载页面,我需要知道在组件上设置的数字...我怎么能得到这个数?

//my layout code
function onOpenWorkList()
{

    $this['works'] = Category::where('slug', input('slug'))->first();

    $this['categories'] = Category::all();

    $this['active_category'] = input('slug');

    $this['perPage'] = "";  // HERE IS THE CODE

    return [
        '.home_categories' => $this->renderPartial('work_list_categories_post'),
        '.container' => $this->renderPartial('work_list')
    ];
}

enter image description here

php ajax laravel octobercms octobercms-backend
2个回答
0
投票

在您的组件文件中:

public $perPage;

/* ... */

public function init()
{
    $this->perPage = $this->property('perPage');
}

然后,在布局中,您可以这样做:

function onOpenWorkList()
{
    $this['works'] = Category::where('slug', input('slug'))->first();

    $this['categories'] = Category::all();

    $this['active_category'] = input('slug');

    $_component = $this->components['builderList']; // Get the component

    $this['perPage'] = $_component->perPage; // Get $perPage from component

    return [
        '.home_categories' => $this->renderPartial('work_list_categories_post'),
        '.container' => $this->renderPartial('work_list')
    ];
}

就个人而言,我只是将onOpenWorkList()函数放入组件文件中(而不是布局代码中),因为当它在那里时仍然可以通过ajax访问它,然后你就不必像在中那样获取组件了。上面的例子。


0
投票

从PHP区域的Builder组件获取属性应该在onEnd函数中使用:

    function onEnd()
    {
        $component = $this->page->components['builderDetails']->record
    }
© www.soinside.com 2019 - 2024. All rights reserved.