Question

I wana create a front-end joomla component and this is my first experience.

here is important things:

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;
 }

}

I can print the query result on default.php on view folder! but I wana another thing.

I have a form like this in the front page of my site in a custom module:

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

Now!

I do not know how can I send this form (with post method) to getListQuery() function in model folder...how can do it?

i wana when sb click submit form, the component filter query sql according to values of form and then show new result to user!

i googled for hourse but no chance to solve. thanks for your help.

Était-ce utile?

La solution

You can submit Form from module to component as follows.

Suppose your component name is com_helloworld The in your module form should have the following things.

<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>

In this example your controller file should have my_controller_fun method from controller to model you can use regular method. This methods will get all the form data in your controller , then you can pass that to model.

Detailed :

In your controller file.

 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 
 }

Hope its help..

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top