Key Value list Topic is solved

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
hansen77

Key Value list

Post by hansen77 » Wed Aug 29, 2007 8:33 pm

Hy,

I'm new in Joomla and PHP.
I have a question about listing key value pairs. I want to make my own component. For this I want that the user can add some properties in the admin part. I want that the admin can enter the data like this (the data are separated by \n):
Date=29. August 2007
Name=mr. xyz
Value1=17,3

Now I want do to something like this:

foreach ($params as $KeyValueItem)
{
echo '' .$KeyValueItem->key .'';
echo '' .$KeyValueItem->value .'';
}

I try it with: mosParseParams, JParams, explode, ... but it ditn't work.
Pleas help.

Thanks in advance,

Hansen

User avatar
jalil
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 128
Joined: Wed Jul 04, 2007 4:54 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Key Value list

Post by jalil » Sat Sep 08, 2007 7:43 am

hansen77 wrote:Hy,

I'm new in Joomla and PHP.
I have a question about listing key value pairs. I want to make my own component. For this I want that the user can add some properties in the admin part. I want that the admin can enter the data like this (the data are separated by \n):
Date=29. August 2007
Name=mr. xyz
Value1=17,3

Now I want do to something like this:

foreach ($params as $KeyValueItem)
{
echo '' .$KeyValueItem->key .'';
echo '' .$KeyValueItem->value .'';
}

I try it with: mosParseParams, JParams, explode, ... but it ditn't work.
Pleas help.

Thanks in advance,

Hansen


foreach ($params as $Key=>$ValueItem)
{
echo '' .$Key.'';
echo '' .$ValueItem.'';
}
echo "

now buy me a free beer

";

User avatar
plamendp
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Sun Nov 13, 2005 10:41 am
Location: Varna, Bulgaria

Re: Key Value list

Post by plamendp » Tue Sep 11, 2007 9:33 am

or ...

Code: Select all


while ( list($k, $v) = each($params) ) {
    echo '<td>' . $k . '</td>';
    echo '<td>' . $v . '</td>';
}
echo " <h1>now buy me a free beer</h1>";




Was it TIMTOWD ?  :)


Plamen(dp)
Some day I'll change my signature to something meaningful...some day...

User avatar
ianmac
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 237
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: Key Value list

Post by ianmac » Tue Sep 11, 2007 12:32 pm

It was my impression he wanted to be able to edit the values.  You guys don't seem to account for this.

I would start by creating a config.xml file in the root directory of my component.  It might look like:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>

<config>

   <params>

      <param name="show_noauth" type="radio" default="0" label="Show UnAuthorized Links" description="TIPLINKS">

         <option value="0">No</option>

         <option value="1">Yes</option>

      </param>

      <param name="show_title" type="radio" default="1" label="Show Article Title" description="Show/Hide the articles title">

         <option value="0">Hide</option>

         <option value="1">Show</option>

      </param>

      <param name="link_titles" type="radio" default="0" label="Linked Titles" description="TIPIFYESTITLECONTENTITEMS">

         <option value="0">No</option>

         <option value="1">Yes</option>

      </param>

      <param name="show_intro" type="radio" default="1" label="Show Intro Text" description="Show/Hide the intro text">

         <option value="0">Hide</option>

         <option value="1">Show</option>

      </param>

      <param name="@spacer" type="spacer" default="" label="" description="" />

      <param name="show_section" type="radio" default="0" label="Section Name" description="PARAMSECTION">

         <option value="0">Hide</option>

         <option value="1">Show</option>

      </param>

   </params>

</config>

Then, in my view I would add the code:

Code: Select all

JToolBarHelper::preferences('com_example', '550');


This allows you to do global parameters for your component.

Ian
Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!


Post Reply