Page 1 of 1

Key Value list

Posted: Wed Aug 29, 2007 8:33 pm
by hansen77
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

Re: Key Value list

Posted: Sat Sep 08, 2007 7:43 am
by jalil
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

";

Re: Key Value list

Posted: Tue Sep 11, 2007 9:33 am
by plamendp
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)

Re: Key Value list

Posted: Tue Sep 11, 2007 12:32 pm
by ianmac
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