繁体   English   中英

Joomla模块中的变量

[英]Variable in Joomla Module

我把头砸到墙上....我在helper.php中制作了一个简单的joomla模块,我无法分配从表单中发布的值。

<?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
        }   
    }

?>

我也尝试过不使用具有相同零效果的构造函数:(

<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

class modReservationHelper {
    public $name;
    public $email;
    public $message;
    public $comment;


    function  getValues() {
        $this->name = $_POST['fullname'];
        $this->email = $_POST['email'];
        $this->message = $_POST['message'];
        $this->comment = $_POST['comment'];
    }

     function validateForm() {
        modReservationHelper::getValues;
        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
        }   
    }

?>

如果在mod_wreservation.php中使用它会更好

$post = JRequest::get('post');
$helperObj = new modReservationHelper();
$helperObj->setValue($post);
$helperObj->validateForm();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM