【发布时间】:2014-04-20 16:05:22
【问题描述】:
我面临一个问题(因为我对 Joomla 组件开发比较陌生)关于如何在我的 Joomla 自定义组件的 controller.php 中的两个函数之间传递值
下面是我的controller.php文件
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
JHtml::script(Juri::base() . 'templates/googlemaps/navigation.js');
/**
* Hello World Component Controller
*/
class HelloWorldController extends JControllerLegacy
{
function display(){
echo '<form action="'. echo JRoute::_('index.php?option=com_helloworld&controller=helloworld&task=displayData') .'" method="post">';
echo '<h1>This is Insert Task</h1><br><input type="text" id="name" placeholder="Name"><br>';
echo '<input type="text" id="surname" value="surname" name="surname" placeholder="Surname">';
echo '<input type="submit" value="submit">';
echo '</form>';
}
function delete(){
$id=JRequest::getVar('id');
echo "You want to delete $id";
}
function displayData(){
$name=JRequest::getVar('name');
$surname=JRequest::getVar('surname');
//$mainframe =& JFactory::getApplication();
//$stateVar = $mainframe->getUserStateFromRequest( "$option.state_variable", "surname", "Hello" );
echo "Your name is $name and surname is $surname";
//**How can i get the name and surname variables here after the page refreshes and this task loads**
}
}
我在控制器的 Display() 任务中有两个表单字段,我想在名为 displayData() 的另一个任务中获取我在这些字段中输入的值。 我想出的唯一方法是使用表单的 post 方法并通过 $_POST[ ] 方法获取变量。 Joomla 提供用户状态和变量以及所有这些东西,但我不知道如何在这里使用它们。
【问题讨论】:
-
您在使用 1.5 吗?您是否有理由不能使用当前的 api?还有一个完整的 googlemaps 内置 api,你可能想看看。
-
等等,你不能在 1.5 中,但你为什么要使用 JRequest?
-
我正在使用 Joomla 2.5,很抱歉,但我想不出另一种方法在控制器(或其不同视图)中的两个任务之间传输数据,而不是 JRequest。关于 joomla 的 googlemaps 内置 api...你能给我提供任何相关的链接吗?
-
JRequest 已弃用,请改用 JInput。 docs.joomla.org/Retrieving_request_data_using_JInput。对于 API,它位于您的库文件夹中
libraries/joomla/google/embed/maps.php。
标签: php joomla components