【问题标题】:how pass form from module to component in joomla 3.1如何在 joomla 3.1 中将表单从模块传递到组件
【发布时间】:2013-09-02 15:38:54
【问题描述】:

我想创建一个前端 joomla 组件,这是我的第一次体验。

这里有重要的事情:

1-component/controller.php

class TestController extends JControllerLegacy
{
public function display($cachable = false, $urlparams = false)
{

$view= JFactory::getApplication()->input->getCmd('view','items');
    JFactory::getApplication()->input->set('view', $view);
    parent::display($cachable, $urlparams);
}
}

2:com_test/model/items.php

<?php
defined('_JEXEC') or die();

jimport( 'joomla.application.component.modellist' );


class TestModelItems extends JModelList
{
    public function __construct($config = array())
    {
    if (empty($config['filter_fields'])) 
        $config['filter_fields'] = array('id', 'title', 'catid');
    parent::__construct($config);
}

function getListQuery()
{
    $db = JFactory::getDBO();
    $query = $db->getQuery(true);
    $query->select(...)
   return $query;
 }

}

我可以在视图文件夹的default.php上打印查询结果! 但我想要另一件事。

我的网站首页的自定义模块中有这样的表单:

<form action="" method="post">
<input type="text"  name="wordsearch" value="search">
.
.
<input type="submit" />
</form>

现在!

我不知道如何将这个表单(使用 post 方法)发送到模型文件夹中的 getListQuery() 函数...怎么做?

我想当某人点击提交表单时,组件根据表单的值过滤查询sql,然后向用户显示新的结果!

我用谷歌搜索了几个小时,但没有机会解决。感谢您的帮助。

【问题讨论】:

    标签: forms joomla components jinput


    【解决方案1】:

    您可以按如下方式从模块到组件提交表单。

    假设你的组件名是com_helloworld 在你的模块表单中应该有以下内容。

    <form action="" method="post">
    <input type="text"  name="wordsearch" value="search">
    .
    .
    <input type="hidden" name="option" value="com_helloworld" />
    <input type="hidden" name="view" value="yourview" />
    <input type="hidden" name="task" value="my_controller_fun" />
    <input type="hidden" value="your_controller_file_name" name="controller">
    <input type="submit" />
    </form>
    

    在这个例子中,你的控制器文件应该有 my_controller_fun 从控制器到模型的方法,你可以使用常规方法。此方法将获取控制器中的所有表单数据,然后您可以将其传递给模型。

    详细:

    在您的控制器文件中。

     function my_controller_fun(){
         $post_array = $_POST;
         $model = $this->getModel('Profile', 'UsersModel');//example for including profile model you can specify your model file name
         $model->function_inyourmodel($post_array);//this function should be in model 
     }
    

    希望它的帮助..

    【讨论】:

    • 谢谢,但这正是我的问题!如何编写 my_controller_fun() 函数?以及如何将其传递给模型?
    猜你喜欢
    • 1970-01-01
    • 2013-08-25
    • 2013-06-05
    • 2013-12-11
    • 2011-08-11
    • 2014-09-18
    • 1970-01-01
    • 2013-09-14
    • 2013-08-26
    相关资源
    最近更新 更多