Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC:

populateObjects(&$item) "infinite" children... 10 Apr 2013 13:29 #7039

Hi Gez / other interested cooks

The populateObjects method in Cook is one of the features I am very interested in since it facilitates a number of my current tasks. The code below shows my implementation of recursive object population within the j-cook framework itself.

The code is inserted into the empty populateObjects method in the ‘jmodel.list.php’ file in the 'classes' folder of a given component. Based on the current j-cook environment, it is called each time a collection object is built. You can therefore populate the items in a given collection with "infinite" additional children.

Regards
v

Let me know if this helps or ways in which it can be improved, thanks.


	/**
	* Prepare other additional related objects.
	*
	* @access	public
	* @param	array	&$items	The objects to populate.
	* @return	void
	*/
	public function populateObjects(&$items)
	{
		if (!isset($items) || empty($items))
			return;

		$model = JModel::getInstance($this->view_item, 'xxxModel');
		foreach ($items as &$item)
		{
			if ( $model && method_exists( $model, 'populateObjects' ) )
			{
				$model->populateObjects($item);

			}

		}

	}

Please Log in or Create an account to join the conversation.

Last edit: by vlemos.
  • Page:
  • 1
  • 2
Time to create page: 0.063 seconds

For starters it's just so easy to design an app in a way that I'm used to i.e. database first then views followed by customization. The fork system is pure brilliance from a developer standpoint as I can override things and still add and update my projects with minimal effort! Truly amazing to be able to build components in Joomla using incremental refinement without having to do everything by hand. Thanks for the great tool! I am so much more productive now than ever and I can't imagine building components any other way!!!!
Dave (Forum)

Get Started