我有这段代码来呈现模板(我是 PHP 新手,所以请耐心等待)
function __destruct()
{
/*
* It's render the template
*
*/
$this->_template->render();
}
出现此错误:
Fatal error: Call to a member function render() on a non-object in /opt/lampp/htdocs/soap/php/library/controller.class.php on line 73
这是构造
function __construct($model, $controller, $action)
{
/*
* A default constructor which creates objects of the template and model
* @param string model, controller and action.
* @return
*/
$this->_controller = $controller;
$this->_action = $action;
$this->_model = $model;
$this->$model = new $model;
$this->_template = new Template($controller,$action);
}
如果您认为我应该添加更多内容,请告诉我。我是 PHP 新手,正在尝试让这个应用程序正常工作。欢迎任何想法!
更新:全班
<?php
/*
*
* controller.class.php - Controller class will be used as the base class
* for all our controllers
*
*
* The above class is used for all the communication between the controller,
* the model and the view (template class). It creates an object for the
* model class and an object for template class. The object for model class
* has the same name as the model itself
*
*
* We are not including the ?\> to avoid injection of any extra whitespaces in our output.
*
*
*/
class Controller extends Validation
{
protected $_model;
protected $_controller;
protected $_action;
protected $_template;
// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
function __construct($model, $controller, $action)
{
/*
* A default constructor which creates objects of the template and model
* @param string model, controller and action.
* @return
*/
$this->_controller = $controller;
$this->_action = $action;
$this->_model = $model;
$this->$model = new $model;
$this->_template = new Template($controller,$action);
}
// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
function set($name,$value)
{
/*
* Set the variables from the controller to the template as a variables.
* @param string name,value
* @return
*/
$this->_template->set($name,$value);
}
// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
function __destruct()
{
/*
* It's render the template
*
*/
$this->_template->render();
}
}
验证类:
<?php
/*
*
* pdoconnectionclass.php - Validation is used to validate any input data to the website
*
*
* The above class is used for checking every data that are the user wrote it and are going
* to be stored in the database. For each type of input there is an appropriate function
* to check it before is going to be store in the database.
*
*
* We are not including the ?\> to avoid injection of any extra whitespaces in our output.
*
*
*/
class Validation
{
public function isEmpty($check_var)
{
/** Check if the input value is empty or not
* If is empty then return true back on the main program
* else return false
*/
if (empty($check_var)){
return true;
}
else
{
return false;
}
}
public function isInt($check_var)
{
/** Check if the input value is integer
* and if Yes then return false else if not and is not int return false
*/
if (is_int($check_var)) {
return true;
}
else
{
return false;
}
}
public function isPositive($check_var)
{
/** Check if the input value is positive
* and if Yes then return false else if not and is not int return false
*/
if ($check_var > 0)
{
return true;
}
else
{
return false;
}
}
public function checking_phone($check_var)
{
/** Check if the input value is a phone
Check if the if the characters of $check_var
are equal to 14 if the value has 0044 or if are 11
if they start from 07. Then check if is positive
and then removes the 0 from 07 and adds 44 at the beginning
*/
if (strlen($check_var) == 11)
{
if ($this->isPositive($check_var) == true)
{
if (($check_var >= '07000000000') && ($check_var <= '07999999999'))
{
$temp_phone = "44";
$temp_phone .= substr($check_var, 1);
return $temp_phone;
}
else
{
return false;
}
}
else
{
return false;
}
}
else if (strlen($check_var) == 14)
{
if ($this->isPositive($check_var) == true)
{
if (($check_var >= '00447000000000') && ($check_var <= '00447999999999'))
{
$temp_phone = substr($check_var, 2);
return $temp_phone;
}
else
{
return false;
}
}
else
{
return false;
}
}
else if (strlen($check_var) == 12)
{
if ($this->isPositive($check_var) == true)
{
if (($check_var >= '447000000000') && ($check_var <= '447999999999'))
{
return $check_var;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
public function checkforXSS($check_var)
{
/** Gets the input value and prevents HTML from being embedded,
and therefore prevents JavaScript embedding as well.
Return a safe versions of the input.
The htmlentities() function converts both double and single
quotation marks to entities and the text to ASCII compatible multi-byte 8-bit Unicode.
*/
htmlentities( $check_var, ENT_QUOTES, 'utf-8' );
return $check_var;
}
public function filter_var_int($var)
{
/** Filters a variable with the specified filter.
*/
return filter_var($var, FILTER_SANITIZE_NUMBER_INT);
}
public function filter_var_string($var)
{
/** Filters a variable with the specified filter.
*/
return filter_var($var, FILTER_SANITIZE_STRING);
}
public function filter_var_email($var)
{
/** Filters a variable with the specified filter.
*/
$temp = '';
$temp = filter_var($var, FILTER_SANITIZE_EMAIL);
$temp = filter_var($temp, FILTER_VALIDATE_EMAIL);
return $temp;
}
public function create_salt_password($username)
{
/** Creates a hash value for the password using
a prefixed random unique identifier value with a static characters and the username
*/
$salt = hash('sha256', uniqid(mt_rand(), true) .AUTH_SALT .strtolower($username));
return $salt;
}
public function get_activation_code()
{
/** Creates an activation code for the user
*/
return md5(uniqid(rand(), true));;
}
}