Recovery of a Form in Module
Moderators: ooffick, General Support Moderators
Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
-
- Joomla! Enthusiast
- Posts: 140
- Joined: Tue Sep 22, 2015 1:04 pm
- Location: St palais sur mer, France
Recovery of a Form in Module
I explain myself following a search I get a form on my page ($thid->items). I would like to retrieve the information in a module that I created.
I thought I could retrieve the info by the model but it does not work.
$model = $app->bootComponent('com_xxx')->getMVCFactory()->createModel('Books', 'Site', ['ignore_request' => true]);
$results = $model->getItems();
Thanks for your help
I thought I could retrieve the info by the model but it does not work.
$model = $app->bootComponent('com_xxx')->getMVCFactory()->createModel('Books', 'Site', ['ignore_request' => true]);
$results = $model->getItems();
Thanks for your help
-
- Joomla! Explorer
- Posts: 329
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Re: Recovery of a Form in Module
Presumably you're getting the full result without taking any notice of the search items the user entered?
"It doesn't work" doesn't give us much of a hint as to what exactly is going wrong.
Since you're coming at it from a module not the component you probably need to do the work to generate the user state (from the query) to recreate the the exact result you're looking for. I'm not certain you can do it the same way, you may need to get a little creative.
If you look at the model code ("getListQuery"?) you'll be able to find the things that need to be set.
"It doesn't work" doesn't give us much of a hint as to what exactly is going wrong.
Since you're coming at it from a module not the component you probably need to do the work to generate the user state (from the query) to recreate the the exact result you're looking for. I'm not certain you can do it the same way, you may need to get a little creative.
If you look at the model code ("getListQuery"?) you'll be able to find the things that need to be set.
It's a community, the more we all contribute, the better it will be.
-
- Joomla! Enthusiast
- Posts: 140
- Joined: Tue Sep 22, 2015 1:04 pm
- Location: St palais sur mer, France
Re: Recovery of a Form in Module
Thank you Mark for this piece of research. What I want exactly is to create a module capable of filtering the result of my search visible in the body of my site. To do this, I would already have to retrieve the search query for my component via the model. That's what I can't do
-
- Joomla! Explorer
- Posts: 329
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Re: Recovery of a Form in Module
Indeed. You can't do it because you can't access the component's instance of the model.
So I'm suggesting looking at how the component fills the state (user or otherwise) from the screen form in the query, and then fill that state yourself (from the screen form) and then you'll be able to create the same result.
So I'm suggesting looking at how the component fills the state (user or otherwise) from the screen form in the query, and then fill that state yourself (from the screen form) and then you'll be able to create the same result.
It's a community, the more we all contribute, the better it will be.
-
- Joomla! Enthusiast
- Posts: 140
- Joined: Tue Sep 22, 2015 1:04 pm
- Location: St palais sur mer, France
Re: Recovery of a Form in Module
https://joomdonationdemo.com/eshop/
the module "Eshop Products Filter" is what i want to do.
the module "Eshop Products Filter" is what i want to do.
-
- Joomla! Enthusiast
- Posts: 140
- Joined: Tue Sep 22, 2015 1:04 pm
- Location: St palais sur mer, France
Re: Recovery of a Form in Module
oops! I don't know if I'm smart enough to do this. Could one of the functions of the model help you?
Model
Model
Code: Select all
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_xxx', 'filter_books', array('control' => 'jform','load_data' => $loadData));
if (empty($form))
{
return false;
}
return $form;
}
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'title', 'b.title','book_title',
);
}
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
$input = $app->input;
$context = $this->context; //com_xxx.items
...
// List state information.
parent::populateState($ordering, $direction);
}
public function getItems()
{
$items = parent::getItems();
return $items;
}
Last edited by Per Yngve Berg on Tue Jul 12, 2022 9:25 am, edited 1 time in total.
Reason: Added code tags around code
Reason: Added code tags around code
-
- Joomla! Explorer
- Posts: 329
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Re: Recovery of a Form in Module
Yes... ummm... no. These snippets don't help.
It's the code (should be in your getListQuery method) that sets up "where" clauses for your query.
I've got stuff like that in some of my code, for example
You must (surely?) have something like this if you're letting people put in search criteria.
It's the code (should be in your getListQuery method) that sets up "where" clauses for your query.
I've got stuff like that in some of my code, for example
Code: Select all
$language = $this->getState('filter.language');
if ($language)
{
$query->where('a.language = ' . $db->quote($language));
}
It's a community, the more we all contribute, the better it will be.
-
- Joomla! Enthusiast
- Posts: 140
- Joined: Tue Sep 22, 2015 1:04 pm
- Location: St palais sur mer, France
Re: Recovery of a Form in Module
that's right. I have in the function getListQuery a lot of where with a return $query to finish. This is what I would like to retrieve in my module so that I can work on it
Last edited by Slushgood on Thu Jul 07, 2022 2:18 pm, edited 1 time in total.
-
- Joomla! Enthusiast
- Posts: 140
- Joined: Tue Sep 22, 2015 1:04 pm
- Location: St palais sur mer, France
Re: Recovery of a Form in Module
by associating the namespace I access the getListQuery() request but it returns an error
0 Call to protected method J4x\Component\xxx\Site\Model\BooksModel::getListQuery() from context 'Joomla\CMS\Dispatcher\ModuleDispatcher'
even if i made it public
0 Using $this when not in object context
0 Call to protected method J4x\Component\xxx\Site\Model\BooksModel::getListQuery() from context 'Joomla\CMS\Dispatcher\ModuleDispatcher'
even if i made it public
0 Using $this when not in object context
-
- Joomla! Enthusiast
- Posts: 140
- Joined: Tue Sep 22, 2015 1:04 pm
- Location: St palais sur mer, France
Re: Recovery of a Form in Module
Apparently I have to save the result in a session variable.
How and where to create this session variable?
How and where to create this session variable?
-
- Joomla! Explorer
- Posts: 329
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Re: Recovery of a Form in Module
Let me Google that for you...
You could try viewtopic.php?t=605099, the first one that came up.
Notice it's very old, but it looks like it might work. You want "Session" not "JSession", but other than that it looks plausible.
You could try viewtopic.php?t=605099, the first one that came up.
Notice it's very old, but it looks like it might work. You want "Session" not "JSession", but other than that it looks plausible.
It's a community, the more we all contribute, the better it will be.