How to configure component so every extension can read from it?

58 views
Skip to first unread message

Oen44

unread,
Jan 17, 2018, 9:48:09 AM1/17/18
to Joomla! General Development
Hello,

I've made my first component based on https://docs.joomla.org/J3.x:Developing ... _Component. Everything works fine as I want. I have a list of products that can be added, edited etc. from control panel. I'm not displaying each product separately but all at the same time on single page. There is also range slider and I want clients to change values (like min, max) for that slider, using configuration from control panel. By following https://docs.joomla.org/J3.x:Developing ... figuration I know that every product has it's own 'params' value and changing something in global configuration won't affect products already created.
From here https://docs.joomla.org/J3.x:Developing ... ic_backend I got list of products to save and read from database. They got simple values like name, description, price and image (well, that's all actually). In frontend I'm reading all products at once and then display on the page.

Frontend: https://i.imgur.com/HLB0mlg.png
Backend: https://i.imgur.com/QXI0OGC.png
Configuration: https://i.imgur.com/6n80Bv4.png

How can I make that configuration so every product will read from it?

oeN. oeN.

unread,
Jan 17, 2018, 10:09:51 AM1/17/18
to Joomla! General Development

Marvin_Martiano

unread,
Jan 18, 2018, 12:31:19 PM1/18/18
to Joomla! General Development
Sounds like not the PRODUCT should read, but the VIEW? E.g. “display any product between MinPrice upto MaxPrice”, no reason why each product should know parameters like these. That would just be loads of database writes if large catalog, for no benefit?

I may overlook something.
MM

oeN. oeN.

unread,
Jan 18, 2018, 5:59:09 PM1/18/18
to Joomla! General Development
That's not what I meant. By following this documentation https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_configuration we can add menu entry to Global Configuration. That's where I store some values and want to use them in a view. I need something that will return array/object of settings and their values that are stored in components configuration. But in the documentation those settings are stored separately for every added entry in PARAMS table column.  I don't need that, all I want to get settings from configuration.

Michael Babker

unread,
Jan 18, 2018, 6:30:31 PM1/18/18
to joomla-de...@googlegroups.com
It sounds like you want something like what most core components have where you have some parameters set in the component's configuration and you want those things to also be customizable either through menu item parameters or specific to that product.  For those cases, you would need to get the data from the various parameter sources and merge it into a single registry.  If you look in core, com_content's article view has a scenario similar to what you're aiming for.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send email to joomla-dev-general@googlegroups.com.

oeN. oeN.

unread,
Jan 18, 2018, 7:03:52 PM1/18/18
to Joomla! General Development
I actually found simple solution to my problem.
      $query = $db->getQuery(true);
      $query
->select('`params`')
           
->from('#__extensions')
           
->where('element=\'com_aquaoferta\'');
      $db
->setQuery((string)$query);

      $tempParams
= $db->loadObject();
      $params
= new JRegistry;
      $params
->loadString($tempParams->params, 'JSON');
      $this
->items['params'] = $params;
That's all. Now I can use those configuration values in frontend view.

Chris Davenport

unread,
Jan 20, 2018, 7:13:31 AM1/20/18
to joomla-de...@googlegroups.com
I think

$this->items['params'] = ComponentHelper::getParams('com_aquaoferta');

will achieve the same result.

Chris.


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send email to joomla-dev-general@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.



--
Chris Davenport
Joomla Production Leadership Team

Oen44

unread,
Jan 20, 2018, 9:36:17 AM1/20/18
to Joomla! General Development
You are right! Thank you!


W dniu sobota, 20 stycznia 2018 13:13:31 UTC+1 użytkownik Chris Davenport napisał:
I think

$this->items['params'] = ComponentHelper::getParams('com_aquaoferta');

will achieve the same result.

Chris.

On 19 January 2018 at 00:03, oeN. oeN. <oen...@gmail.com> wrote:
I actually found simple solution to my problem.
      $query = $db->getQuery(true);
      $query
->select('`params`')
           
->from('#__extensions')
           
->where('element=\'com_aquaoferta\'');
      $db
->setQuery((string)$query);

      $tempParams
= $db->loadObject();
      $params
= new JRegistry;
      $params
->loadString($tempParams->params, 'JSON');
      $this
->items['params'] = $params;
That's all. Now I can use those configuration values in frontend view.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send email to joomla-de...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages