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 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码