2011-01-27 4 views
0

Я обрушиваю голову на стену ... Я делаю простой модуль joomla, в 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();

+0

Как вы вызывающая функция класса modReservationHelper? – Gaurav

+0

См. Выше edit. – Jim

ответ

2

Вы вызываете класс в статической форме. Таким образом, $ это в классе не будет объектом 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(); 
+0

1st option i get: Fatal error: Call to protected modReservationHelper :: __ construct() из контекста 'JModuleHelper' – Jim

+0

oops..I не заметил. Сделать эту функцию __contruct общедоступной. – Gaurav

+0

спасибо, уже сделал это .... и он работает :) большое спасибо – Jim

Смежные вопросы