最近MVCを学んでいます。Web サイトを MVC 構造に再構築しようとしていますが、別の名前の空間内で関数を呼び出すのに問題があります (おそらく、OOP についてあまり知りません)。これが私のコードです:
namespace UserFrosting;
class GroupController extends \UserFrosting\BaseController {
public function testFunction($params){
//Simple test function that i had error: Call to undefined function UserFrosting\testFunction()
$params['Password'] = $pw;
$params['JSON'] = 'Yes';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
if (curl_errno($curl)) $obj = (object) array('Result' => 'Error', 'Error' => curl_error($curl));
else if (empty($response)) $obj = (object) array('Result' => 'Error', 'Error' => 'Connection failed');
else $obj = json_decode($response);
curl_close($curl);
return $obj;
}
public function loginNumber(){
$params = array("Command" => "SystemStats");
$api = testFunction($params);
echo "<h3>Server Status</h3>\r\n";
if ($api -> Result == "Error") die("Error: " . $api -> Error);
echo "Logins: " . $api -> Logins . "<br/>\r\n";
}
}
したがって、基本的に私は を呼び出しloginNumber()
、このエラーが表示されます:* 未定義関数 UserFrosting\testFunction() への呼び出し*
私は同じ問題を抱えていましSoupClient
たが、私はこのエラーを示しています:* クラス 'UserFrosting\SoapClient' が見つかりません* ここsoapClient
に同じ名前空間の私のコードがあります:
public function templatePost(){
$client = SoapClient('https://www.test.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']);
$result = $client->PaymentRequest([
'MerchantID' => $MerchantID,
'Amount' => $Amount,
'Description' => $Description,
'Email' => $Email,
'Mobile' => $Mobile,
'CallbackURL' => $CallbackURL,
]);
if ($result->Status == 100) {
header('Location: https://www.test.com/pg/StartPay/'.$result->Authority);
} else {
echo'ERR: '.$result->Status;
}
}
同じエラーが発生しました。何が問題なのですか? これらの関数を呼び出すにはどうすればよいですか?