Dynamic Values in <Params> in component.xml [J1.0]

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
ichneumon
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Mar 07, 2008 8:27 pm

Dynamic Values in <Params> in component.xml [J1.0]

Post by ichneumon » Fri Mar 07, 2008 9:43 pm

Is there any way to dynamically set the values in the Parameters section of a menu item? Specifically, I'd like to populate a select field with options pulled through from a db.
For example, I have the following in my component.xml

Code: Select all

    <params>
       <param name="category" type="list" default = "0" label="Display Category" description="Test">
         <option value="0">First</option>
         <option value="1">Second</option>
         <option value="2">Third</option>
      </param>
I need to replace these with values selected from one of the component's dbs, so that it becomes something like:

Code: Select all

<option value="<?php echo $id; ?>"><?php echo $name; ?></option>
for each value found. Is there any way to tell Joomla to update the relevant xml values while parsing?
My current workaround is to use a url link with the $id value added by hand, but this is not very flexible, or convenient for the content managers. Fortunately, it's not a value that will change very often, but I'd prefer a more elegant approach.

Bodom78
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Fri Nov 04, 2005 9:23 am

Re: Dynamic Values in <Params> in component.xml [J1.0]

Post by Bodom78 » Sat Mar 08, 2008 2:11 am

You could create the options in your view like this based on the database call to pull the required items.

ichneumon
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Mar 07, 2008 8:27 pm

Re: Dynamic Values in <Params> in component.xml [J1.0]

Post by ichneumon » Sat Mar 08, 2008 8:16 am

Thanks Bodom78 - however, I have no problem creating the dropdown (I'm an experienced php/mySQL coder, just new to Joomla). The question is aimed at whether I can get these values into the parameters section of a Component menu item. Also, from my reading so far, Joomla 1.0x doesn't have the MVC framework implemented. I'm updating an existing site, and upgrading isn't currently feasible.

Bodom78
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Fri Nov 04, 2005 9:23 am

Re: Dynamic Values in <Params> in component.xml [J1.0]

Post by Bodom78 » Sat Mar 08, 2008 5:26 pm

I believe if your setting you params in the component .xml then their generally preset unless its a core list like Joomla's categories.

You can create custom radio options, or drop downs from within your component by using the mosHTML class for Joomla 1.0.x. You can find a list of it's functions and examples here.

Just fill the arrays to generate the radio or drop down lists with queries from your database.

Hope that helps.


Post Reply