0
我的代碼有些問題。我想在方法調用對象數組值,BU具有錯誤:調用方法PHP中的對象數組
說明:未定義變量:login_error在 C:\ XAMPP \ htdocs中\前端\控制器\ Users.php第27行
注意:試圖讓非對象的財產 C:\ XAMPP \ htdocs中\前端\控制器\ Users.php第27行
這是我的控制器Users.php
class Users extends Controller
{
function doLogin(){
if(isset($_POST['zaloguj'])){
Users::error($login_error->empty);
}
}
}
和語言文件,我有我的對象數組。
<?php
$login_error = (object) array(
'empty' => 'ERROR TEXT',
'dberror' => 'ERROR TEXT 2'
);
?>
全局控制器與我的誤差函數:
public function error($text){
echo '<div class="alert alert-danger">
<strong>Błąd!</strong> '.$text.'</div>';
}
public function success($text){
echo '<div class="alert alert-success">
<strong>Brawo!</strong> '.$text.'</div>';
}
public function info($text){
echo '<div class="alert alert-info">
<strong>Uwaga!</strong> '.$text.'</div>';
}
而且裝載機 - 我加載我所有的controlers在一個文件中。
<?php
require_once('config.php');
///////////////////////////////////
// INCLUDING LANGUAGES
///////////////////////////////////
include('frontend/language/pl_PL.php');
///////////////////////////////////
// INCLUDING CONTROLERS
//////////////////////////////////
require_once('frontend/controller/Controller.class.php');
require_once('frontend/controller/Users.php');
//////////////////////////////////
// INCLUDING MODELS
//////////////////////////////////
require_once('frontend/model/model.php');
require_once('frontend/model/Users.php');
?>
'$ login_error'沒有在'doLogin'中定義,所以變量不存在。問題是什麼? –
[參考:什麼是變量作用域,哪些變量可以從哪裏訪問,什麼是「未定義變量」錯誤?](http://stackoverflow.com/questions/16959576/reference-what-is-variable-scope -which-variables-are-accessible-from-where-and) –
如何在Controller類中包含我所有方法的語言文件? 我不想將所有方法中的語言文件逐個包含在內。 –