Jump to content

Efficient database select (MVC)


Redroest
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...