我正在尝试使用 Ajax 从我的页面中运行带有 ExpressonEngine 标记的 PHP 脚本。我已经根据文档设置了 PHP 脚本,但我似乎无法真正调用 PHP 脚本中的函数。我肯定错过了什么。
我的阿贾克斯:
function createNew(obj) {
$.ajax({
url: 'createNew.php',
data: "call=create_new",
type: 'GET',
success: function(data){
obj.innerHTML = data;
}
});
}
我的PHP:
<?php
if($_SERVER['REQUEST_METHOD']=="GET") {
$function = $_GET['call'];
if(function_exists($function)) {
call_user_func($function);
} else {
echo 'Function Not Exists!!' . $function;
}
}
class CreateNewEntry {
public function create_new() {
$this->EE->load->library('api');
$this->EE->api->instantiate('channel_entries');
$this->EE->api->instantiate('channel_fields');
$channel_id = $this->channel_id;
$data = array(
'title' => 'Ny entry',
'entry_date' => time(),
'ping_servers'=> array(),
'url_title' => 'new-entry',
'field_id_2' => '5.0',
'field_id_3' => '10%',
'field_id_4' => 'Author',
'field_id_5' => '4x4',
'field_id_6' => '<p>Some text</p>'
);
if ($this->EE->api_channel_entries->submit_new_entry($channel_id, $data) === FALSE)
{
$errors = $this->EE->api_channel_entries->errors;
echo $errors;
}
echo 'Success';
}
}
?>
起初,我尝试不使用类和函数。但是我在 $this 上遇到了错误,这似乎需要在类内的函数中。所以我就这么做了。但它仍然无法正常工作。有任何想法吗?