wCMF Wiki : ControllerExample

HomePage :: Categories :: PageIndex :: RecentChanges :: Login/Register
This controller get a parameter containing a string and look for all objects of the type "ChiBusinessUseCase" present in the model.
this is an example how to program a controller in wCMF using the Object Query.

<?php

require_once (BASE."wcmf/lib/presentation/class.Controller.php");
require_once (BASE."wcmf/lib/persistence/class.PersistenceFacade.php");
require_once (BASE."wcmf/lib/persistence/class.ObjectQuery.php");
require_once (BASE."wcmf/lib/model/class.Node.php");
require_once (BASE."wcmf/lib/security/class.RightsManager.php");


class AutocompleteController extends Controller
{

  function hasView()
  {
	return true;
  }

	function executeKernel()
	{
	// the ammount of objects that you intent to get.     
	
	$pagingInfo = new PagingInfo($this->_request->getValue('limit'));
	      //Set the current index (selects the page)
	    $pagingInfo->setIndex($this->_request->getValue('start')); 
	    //read an input params
	   $QueryString= $this->_request->getValue('QueryString');

	    // execute this code only if the action is autocomplete
	    if ($this->_request->getAction() == 'autocomplete');

	    //search the object ChiBusinessUseCase
	    $query = & PersistenceFacade::createObjectQuery('ChiBusinessUseCase');
		
		// (ChiBusinessUseCase.name LIKE '%ingo%' AND Author.email LIKE '%wemove%')

	    $chiBUCTpl1 = & $query->getObjectTemplate('ChiBusinessUseCase');        
		$chiBUCTpl1->setValue("Name", $QueryString, DATATYPE_ATTRIBUTE);
		$ChiBusinessObjectList = $query->execute(BUILDDEPTH_SINGLE, null, $pagingInfo); 

	    // set the next action
	    $this->_response->setAction('ok');
		
		//set the response
		 $this->_response->setValue('response', $ChiBusinessObjectList);
		
		//the controller is ready so we return false 
		   return false;
	}
}
?>



Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.1085 seconds