0
當我打電話給我的頁面example.com/do-something時,我想讓我的代碼__cunstruct()
自動執行。自動運行類的方法
<?php
class Ajax {
// POST Manager
public function __construct() {
require_once('../../../wp-load.php');
require_once('intern/functions.php');
$customers = new Customers;
// Save a comment
if (isset($_POST['comment']) && $_POST['comment'] === 'save') {
$this::save_comment();
}
// User has been called
if ($_POST['form_sent'] === 'yes' && (isset($_POST['id']))) {
$this::mark_user_as_complete();
}
// Load a dynamic table for 'closed' customers
if (isset($_POST['customer_status']) && $_POST['customer_status'] === 'abgeschlossen') {
$this::get_closed_customers();
}
// Load a dynamic table for 'open' customers
if (isset($_POST['customer_status']) && $_POST['customer_status'] === 'offen') {
$this::get_open_customers();
}
// Mark the user as 'open' and remove him from the 'closed' list
if ($_POST['customer_uncalled'] === 'yes' && isset($_POST['customer_called_id'])) {
$this::mark_user_as_open();
}
// Show search results
if (isset($_POST['searchValue']) && !empty($_POST['searchValue'])) {
$this::show_search_results();
}
}
}
我認爲__construct()
會使它,但它不輸出任何東西。我怎樣才能讓它自動運行?
不知道我明白這個問題。如果你想讓__construct運行,你需要實例化這個類。即在你想要的地方使用新的Ajax()。 –
另外,你爲什麼使用'$ this ::'之類的東西。你有一個實例,但是你靜態調用方法。您可能需要'$ this->'而不是'$ this ::',或者'self ::',但它依賴於其他類。 –
@JonStirling是的,我知道,但我想也許會有辦法,所以__construct會自行初始化。 –