New Containers in RedFruits version

Posted: October 25, 2010 in development
Tags: , ,

The last release of RedFruits has some changes.

ADContainer

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

<?php
require_once(REDFRUITS_PATH.'gui/ADCoreGui.php');
$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();
$form->add(array(
	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');
?>

ADUList

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:

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

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s