Php Joomla模块中的变量
我的头撞到墙上了。。。。我正在制作一个简单的joomla模块,在helper.php中,我无法分配表单中发布的值Php Joomla模块中的变量,php,class,module,joomla,Php,Class,Module,Joomla,我的头撞到墙上了。。。。我正在制作一个简单的joomla模块,在helper.php中,我无法分配表单中发布的值 <?php // no direct access defined('_JEXEC') or die('Restricted access'); class modReservationHelper { public $name; public $email; public $message; public $comment; pr
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
class modReservationHelper {
public $name;
public $email;
public $message;
public $comment;
protected function __construct() {
$this->name = $_POST['fullname'];
$this->email = $_POST['email'];
$this->message = $_POST['message'];
$this->comment = $_POST['comment'];
}
function validateForm() {
echo $this->name; //The output is always 0
echo $this->email+"</br>";//The output is always 0
echo $this->message;//The output is always 0
//When I try
echo $_POST['comment']; // Is correct
}
}
?>
我也尝试过不使用具有相同零效果的构造函数:(
整个过程是从“mod_wreservation.php”调用的,我调用modReservationHelper::validateForm();您正在以静态方式调用该类。因此类中的$this将不是modReservationHelper的对象 在mod_wreservation.php中使用它的正确方法是
$helperObj = new modReservationHelper(); // your choice will work (__counstruct) with this
$helperObj->validateForm();
第二选择
$helperObj = new modReservationHelper();
$helperObj->setValue();
$helperObj->validateForm();
而课堂将是
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
class modReservationHelper {
public $name;
public $email;
public $message;
public $comment;
function setValues() {
$this->name = $_POST['fullname'];
$this->email = $_POST['email'];
$this->message = $_POST['message'];
$this->comment = $_POST['comment'];
}
function validateForm() {
echo $this->name; //The output is always 0
echo $this->email+"</br>";//The output is always 0
echo $this->message;//The output is always 0
//When I try
echo $_POST['comment']; // Is correct
}
}
?>
如何调用类modReservationHelper的函数?我得到的第一个选项:致命错误:从上下文“JModuleHelper”oops调用受保护的modReservationHelper::u construct()。我没有注意到。将此函数u construct公开。
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
class modReservationHelper {
public $name;
public $email;
public $message;
public $comment;
function setValues() {
$this->name = $_POST['fullname'];
$this->email = $_POST['email'];
$this->message = $_POST['message'];
$this->comment = $_POST['comment'];
}
function validateForm() {
echo $this->name; //The output is always 0
echo $this->email+"</br>";//The output is always 0
echo $this->message;//The output is always 0
//When I try
echo $_POST['comment']; // Is correct
}
}
?>
$post = JRequest::get('post');
$helperObj = new modReservationHelper();
$helperObj->setValue($post);
$helperObj->validateForm();