首页 > 解决方案 > 有没有办法将类内部的变量传递给php外部的函数?

问题描述

我正在编写一个小“显示更多”按钮,该按钮使用 ajax 从服务器检索数组。它似乎与在函数内声明和设置的正常响应一起工作,但我无法从现有类中的变量中检索数据。

namespace Elementor;
class DB_Gallery extends \Elementor\Widget_Base {

    public $dbg_more = array();

    protected function render() {

        //Some code here

        $this->dbg_more[] = array(some data)
    }
}

function db_gallery_loadmore() {
    $db_gallery = new DB_Gallery;
    $response = $db_gallery->dbg_more;
}

我预计这会奏效,但在课堂外却没有。里面一切都像预期的那样工作。我试图传递的数据是一个数组数组。每次必须插入元素时,我都使用这行代码来执行此操作:

$dbg_more[] = array( 'id'=>$image['id'], 'url'=>$image['url'], 'type'=>$image['type'] );

标签: phpajaxwordpress

解决方案


推荐阅读