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

Php 十月CMS |如何从特定页面上安装的组件获取属性值?,php,ajax,laravel,octobercms,octobercms-backend,Php,Ajax,Laravel,Octobercms,Octobercms Backend,我用一个选项“perPage”创建了我的组件,该选项接受一个数字并设置每页works displayer的限制 它与GET实现一起工作非常好。。。但是在我的项目中,我需要在任何地方实现AJAX,所以我需要通过AJAX加载页面,并且我需要知道组件上设置的数字是多少。。。我怎样才能得到这个号码 //my layout code function onOpenWorkList() { $this['works'] = Category::where('slug', input('slug'

我用一个选项“perPage”创建了我的组件,该选项接受一个数字并设置每页works displayer的限制

它与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')
    ];
}

在组件文件中:

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轻松访问,这样您就不必像上面的示例那样获取组件了。

在您的组件文件中:

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轻松访问,这样您就不必像上面的示例那样获取组件了。

从PHP区域的生成器组件获取属性,应在ONED函数中使用:

    function onEnd()
    {
        $component = $this->page->components['builderDetails']->record
    }

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

    function onEnd()
    {
        $component = $this->page->components['builderDetails']->record
    }

粘贴代码为文本而不是图像粘贴代码为文本而不是图像你好,是的,我知道。。但它在组件配置文件中工作。。。我需要在外部获取此值,我无法在布局代码文件中添加此代码:P@IvanDunets对不起,我误解了你最初的问题。我现在已经更新了我的答案。我在A:\xampp\htdocs\framastudio\storage\cms\cache\50\74\default.htm.php(工作列表是组件的别名:)的第26行得到一个错误“未定义索引:工作列表”),您可能需要将数据传递给正在渲染的分区。我建议将此作为一个新问题和相关代码发布,因为这是一个单独的问题。您好,是的,我知道。。但它在组件配置文件中工作。。。我需要在外部获取此值,我无法在布局代码文件中添加此代码:P@IvanDunets对不起,我误解了你最初的问题。我现在已经更新了我的答案。我在A:\xampp\htdocs\framastudio\storage\cms\cache\50\74\default.htm.php(工作列表是组件的别名:)的第26行得到一个错误“未定义索引:工作列表”),您可能需要将数据传递给正在渲染的分区。我建议将此作为一个新问题发布,并附上相关代码,因为这是一个单独的问题。