doujiepin5547 2012-05-09 10:36
浏览 20
已采纳

joomla在视图之间传递变量

I'm in the middle of programming a joomla component, this component will have a multiple step form for registration, the first one containing 2 radio buttons. What is the easiest approach to pass the variable from the radiobutton on to step2? when the user submits the first form the controller is called to display the second step, is there an easier approach to this? Thanks in advance.

Code:

step1 of the form (view code):

<form name="step1" action="<?php echo JRoute::_('index.php option=com_mycomponent&task=mycomponent.register'); ?>" method="POST">
<input type="radio" name="placement" value="0" checked /> Option 1<br />
<input type="radio" name="placement" value="1" /> Option 2<br />
<div class="next" onClick="document.forms['step1'].submit();"></div>
</form>

Controller code to handle mycomponent.register

class mycomponentControllermycomponent extends JController

{

    public function register()

    {
    $this->setRedirect(JRoute::_('index.php?option=com_mycomponent&view=default&layout=step2', false));
    }

}

I would like to pass the value from the radio to step2 ;)

Hope i didn't miss a topic concerning this already, couldn't find one atleast!

  • 写回答

2条回答 默认 最新

  • dsjojts9734 2012-05-09 11:01
    关注

    In the register method you can access the radio value and then pass it in the link to your view:

        public function register()
        {
            $placementOption = JRequest::getInt('placement', 0, 'post');
    
        $this->setRedirect(JRoute::_('index.php?option=com_mycomponent&view=default&layout=step2&placement=' . $placementOption, false));
        }
    

    In your view of step 2 (view.html.php), you can then access the option in the same way (this time the value is in GET not POST):

    $placementOption = JRequest::getInt('placement', 0, 'get');
    
    $this->assignRef('placement', $placementOption);
    

    Finally, if you want to access it in the views template (e.g. default.php)

    <?php echo $this->placement; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入