簡體   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