Posts Tagged ‘ADContainer’

Redfruits is a stable software to create HML pages or piece of HMTL code, like forms or list.

Now in the last version of redfruits you can use the new ‘insert’ function. This function is present in all the HTML containers (lists, forms, div, fieldsets, etc.). You can insert a component before another component using the id of the second component or by the array index.

For example:

$form = new ADForm();
$form->add(new ADTextField('first_name', 'my first name'));
$form->add(new ADTextField('last_name', 'my last name'));
//new insert function
$form->insert(new ADTextField('year', '2010'), 'last_name');
//Equal to $form->insert(new ADTextField('year', '2010'), 1);
echo $form->render();

Another useful way is to use the other new function in the ADContainer definition: getLastClassStyle($classStyle). This function returns the index of the last component with a given class style. See the next code:


$form = new ADForm();
$form->add(new ADTextField('first_name', 'my first name'))->setClassStyle('style1');
$form->add(new ADTextField('last_name', 'my last name'))->setClassStyle('style2');

$index = $form->getLastClassStyle('style2');
$form->insert(new ADTextField('year', '2010'), $index);

echo $form->render();

RedFruits is growing!!!

See you.

The last release of RedFruits has some changes.


Now you can add an array of components (ADComponent) instead to add one per one. See the next code to see the differences:

The traditional way

$form = new ADForm();
$form->add(new ADLabeledField('Firts name:', new ADTextField('first_name', '', 20, 40)));
$form->add(new ADLabeledField('Last name:', new ADTextField('last_name', '', 20, 40)));
$form->add(new ADSubmit('save', 'save'));
echo $form->render('ADWordpressRender');

The new way

$form = new ADForm();
	new ADLabeledField('Firts name:', new ADTextField('first_name', '', 20, 40)),
	new ADLabeledField('Last name:', new ADTextField('last_name', '', 20, 40)),
	new ADSubmit('save', 'save')
echo $form->render('ADWordpressRender');


In this version you can add children with the new array way using the new function called addContainer.
ADUList is an ADContainer but it’s rendered in different way. Each component added to the ADUList component is rendered within a ‘LI’ tag.
If you want to add more than one component to a ‘LI’ you need to make an ADContainer or use the new function.

The most useful example for this new feature is the classical menu:

	<li>Menu A
			<li> sub menu A 1</li>
			<li> sub menu A 2</li>
	<li>Menu B
			<li> sub menu B 1</li>
			<li> sub menu B 2</li>

With RedFruits:

$menu = new ADUList();
$menu-&gt;addContainer(array (
	'Menu A',
	new ADUList(array(
		'menu A 1',
		'menu A 2'
$menu-&gt;addContainer(array (
	'Menu B',
	new ADUList(array(
		'menu B 1',
		'menu B 2'
echo $menu;

RedFruits is growing!!! That’s all for now.