Jump to content

Efficient database select (MVC)


Redroest

Recommended Posts

Hey people. Im stuck again.I am building a framework based on the Model View Controller principe. My model has an query function like below:

<?php	//Load all default modules   public function getBlockModules()  {			  $sql = 'SELECT * FROM core_modules WHERE blockMode=1';	if(!$ModuleQuery = $this->db->query($sql))	{	  trigger_error('Error in the modulequery: '.$this->db->error);	}	else	{		  $rows = array();		  while($row = $ModuleQuery->fetch_object()) 	  {			  $rows[] = $row;			}			return $rows;	} 	}?>

And my controller function to retreive data looks like this:

<?php	  //Load all blocks	  $modules = $this->Model->getBlockModules();	foreach($modules AS $property)	{		//Load module into the view object			$this->View->setContainer('modules/'.$property->controllerFile, 'modules/'.$property->headerFile, 'themes/Redroest/'.$property->layoutFile, $property->title, $property->positionTag);		}	}?>

As you can see, I need 2 loops in order to keep the data separated from the logic part. Is there a way to prevent multiple loops from happening and still keeping the logics separated?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...