The Act() Function

Description

The act function takes on the parameters (typically from this and get variables, but also arbitrary named parameters), determines the state requested and performs the action of that state. Multiple states can be grouped together to take advantage of shared functionality will typically reside on a single case statement at the beginning of the act function.

The active function returns an array populated with one of the following values:

Constant (1st Element)Meaning2nd Element3rd Element4th Element
GDA_DISPLAY Call render() on this Gadget
GDA_FORWARD Give up Control and Forward to another Gadget Gadget Name State Parameter Array
GDA_GOTOURL Give up control and forward to another URL (for off-site linking ) URL
GDA_FORWARDALIAS Give up control to a common source alias (= 'login-required' or 'security-denied' )
GDA_REPLACE Give up control to be replaced by another object
GDA_FORWARDSUB Give up control to a proxied-gadget GadgetName state parameter array

The act() function can also return a reference to an object with a render() function to be displayed by the layout later.

You may also see:

  return($this->returnTarget(new CReceipt('s-u', 'contact updated,'contact',$contactid ));

This line calculates where to return based on where the user intiated the action from. The returnTarget() function can be called with or without a receipt. The receipt can be used to communicate success or failure to the user and to the page.

Typical Act() Function

Act follows a fairly standard boilerplate for each gadget. Typically the first line initializes the parameters array. The request the state and the parameters from $this→getState(). If this gadget is used to proxy other gadgets than you may see the following line:

	$rline = array ();
	//see if state belongs to contact admin gadget, if so go there...
	if ($this->dispatchToSubGadget(self::$subgadgets, $rline, self::$subparams, $params))
	{
		return ($rline);
	}

That series of lines looks that all the gadgets that are being proxied (self::$subgadgets) and if the state being passed and matches one of those gadgets the first line returns true and populates $rline with the dispatch parameters that are needed. Proxied gadgets are referred to by their controller (parent) and have the same security as their controller. Their states appear in the list of valid states for the controller.

After the dispatch line, typically database connections are established in the function goes into a case statement switched upon the state of the gadget.

The switch statement will contain additional resource allocations, and members of the gadget or other variables to prepare for the eventual display or forwarding as described above.

Join AW and support river stewardship nationwide!