所以我有这个代码片段。
function get_box_ajax() {
global $box;
$box = get_box(); // creates box object
ob_start();
get_template( '/filepath/content.php' );
$output = ob_get_clean();
}
// in the content.php file
global $box;
<form action="<?php echo box_url( $box->url ); ?>" method="post"> // error on this line
...
</form>
因此,使用此代码,我在调用 $box->url 时遇到非对象错误。请注意,这是通过 ajax 完成的。
所以我认为在我的 ajax 函数中我已经全球化了 $box 并且这将需要但它似乎不起作用?有什么想法吗?