In my text the user can input modules which look like this; [[form:contact]], representing a module and its name; [[module:name]
I use the following code to retract this from the text, and split it, get the information from the database I want and replace it.
Is this the best way? It works good, but I’m not sure if this is the most efficient way, and was wondering whay you guys would think of it…
I’m working with the Zend Framework.
This is the code:
$start = strpos($this->view->page->text, "[[");
$end = strpos($this->view->page->text, "]]");
$length = $end-$start+2;
$getModuleTag = substr($this->view->page->text, $start, $length);
$length = $end-$start-2;
$removeTags = substr($getModuleTag, 2, $length);
$split = strpos($removeTags, ":");
$GetModuleSort = substr($removeTags, 0, $split);
$GetModuleName = substr($removeTags, $split+1);
// Get the wanted data from the database
switch($GetModuleSort)
{
case 'form':
$this->result = $this->formsService->GetFormByName($GetModuleName);
$replaceTag = $this->result->elements;
break;
}
// TEST OUTPUT
$final = str_replace($getModuleTag, $replaceTag, $this->view->page->text);
$this->view->finalOutput = $final;
Yes, it’s a good way to do it.