【问题标题】:JToolbar::save() redirectionJToolbar::save() 重定向
【发布时间】:2013-01-14 23:55:47
【问题描述】:

我正在阅读 Joomla 2.5 教程来构建自定义组件。现在我在使用JToolbar::save()JToolBarHelper::cancel 之后遇到了重定向问题。默认情况下,Joomla 想要重定向到默认布局(从编辑布局)。但是我不希望它这样做。我希望它重定向回另一个视图。在 Joomla 1.5 中,我会通过将函数添加到控制器中来完成此操作 - 类似于

function cancel()
{
    //redirects user back to blog homepage with Cancellation Message
    $msg = JText::_( 'COM_BLOG_POST_CANCELLED' );
    $this->setRedirect( 'index.php?option=com_jjblog&view=jjblog', $msg );
}

现在取消功能可以很好地工作,但是对于保存来说,这是一件复杂得多的事情。如果我想覆盖 url,我是否必须将控制器重定向到模型,然后写入模型交互的所有代码?因为这对于像您在 Joomla 1.5 中那样的 url 重定向来说似乎有点过分?

【问题讨论】:

    标签: joomla joomla2.5 joomla-extensions


    【解决方案1】:

    希望您已经添加了具有正确控制器名称的保存工具栏代码,如下所示

    1. JToolBarHelper::save('controllerName.save');
    2. 在适当的控制器中创建保存函数。
    3. 在表单中添加任务
    4. 最后确保您添加了具有相应组件名称的表单操作。

    【讨论】:

      【解决方案2】:

      你可以试试这个-

      首先在控制器中调用父保存函数而不是重定向到 url。

      function save(){
       parent::save();        
       $this->setredirect('index.php?option=com_mycomponent');
      }
      

      【讨论】:

        【解决方案3】:

        好的,它根本不需要$this->setRedirect。只需要我将值更改为

        protected $view_list = 'jjBlog';
        

        然后将所有内容的重定向设置回该列表视图。

        源链接是here

        感谢大家的回复!!

        【讨论】:

          【解决方案4】:

          view.html.php

          protected function addToolbar ()
              {
                  JRequest::setVar ('hidemainmenu', false);
                  JToolBarHelper::title (JText::_ ('Configuration'), 'configuration.gif');
                  JToolBarHelper::save($task = 'save', $alt = 'JTOOLBAR_SAVE');
          
              }
          

          controller.php

          public function save()
              {  
              $mainframe = JFactory::getApplication();
              $mainframe->enqueueMessage (JText::_ ('COM_SOCIALLOGIN_SETTING_SAVED'));    
                  $this->setRedirect (JRoute::_ ('index.php', false));
              }
          

          【讨论】:

            【解决方案5】:

            我认为你可以使用

            global $mainframe;
            $mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
            

            如果您在自定义组件中覆盖 joomla 的默认保存功能,例如

            function save( $task = 'CustomSave', $alt = 'Save' ) // or even same name Save
            

            在您的控制器中,您可以使用 CustomSave 作为任务并使用 $mainframe 进行重定向。

            or
            $mainframe = &JFactory::getApplication();
            $mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
            

            希望对你有所帮助..

            【讨论】:

              猜你喜欢
              • 2014-09-04
              • 1970-01-01
              • 1970-01-01
              • 2021-03-22
              • 1970-01-01
              • 2014-04-13
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多