Home | Forum | Documentation

Code Stylist Documentation





Home | Docs | Entry 13



Use a custom query

Here's an example of a controller function (/db/controllers/posts.php)

function _index( &$vars ) {
  // index controller returns
  // a Collection of recent entries
  extract( $vars );
  return vars(
    array( &$collection, &$profile ),
    get_defined_vars()
  );
}

Here's an example of a controller function with a custom query. The $collection object is defined with the custom query.


function _index( &$vars ) {
extract( $vars );
$collection = $db->get_recordset( 'select posts.created as 
"posts.created", posts.id as "posts.id", posts.title as 
"posts.title", posts.body as "posts.body", posts.contributor as 
"posts.contributor" from posts WHERE posts.entry_id = entries.id and 
entries.person_id = ' . $profile->person_id );
 return vars(

array(

       &$collection,
       &$profile

     ),get_defined_vars());

}









Sign In to post comments







Bookmark this page:








Sign In



Click here to become a member. It's free and convenient.