Welcome Guest, Not a member yet? Register   Sign In
Correct understanding of MVC system?
#1

[eluser]JanDoToDo[/eluser]
Hey guys, Im new to using CI and the MVc method and was hoping for some feedback. Ive seen a lot of posts recently about pagination and a few commetns about what code should go in controllers/views/models. I was hoping you coould comment on my approach below and tell me if I've gone wrong. Anyt thoughts would be hugely appreciateD! thankyou!

Function within controller:
function Top_Rated()
{
//Other code not related to the model
// Set all the configureation for the pagianation system
$config['base_url'] = base_url() . '/boats/Top_Rated';
$config['total_rows'] = ($this -> db -> count_all('video_links') > 100) ? 100 : $this -> db -> count_all('video_links');
$config['per_page'] = '9';
$this -> pagination -> initialize($config);

//Load the search model and name it boat_search
$this -> load -> model('boatsearch_model','boat_search');

//Set the boat_results var for the view as the result of get_boats from the boat_search model(gets passed the num per page, where to start and the order)
$page_info['boat_results'] = $this -> boat_search -> get_boats($config['per_page'], $this -> uri -> segment(3), 'rating' );

// continue with code that isnt to do with model
}

The model:
class Boatsearch_model extends Model
{
var $CI;
var $boat_results;
/*
Constructor
*/
function Boatsearch_model() {
parent::Model();
$this -> table_name = 'video_links';
$this -> CI =& get_instance();
}
function get_boats($resPerPage = 9, $resStart = 0, $sorting = 'rating' )
{
$resStart = is_numeric($resStart) ? $resStart : 0;
//Run the query for the pagination
$boat_search = $this -> CI -> db -> query ( "SELECT * FROM " . $this -> table_name . " ORDER BY $sorting DESC LIMIT $resStart, $resPerPage" );
//Get the resultset from the pagination
$this -> boat_results = $boat_search -> result_array();
//Draw the pagination links and the contents of the array as items on the page
$boat_search = $this -> _draw_results();

//return the results from the draw_results page and set this in the controller as the content for the page body
return $boat_search;
}

function _draw_results()
{
$resultsData = $this -> boat_results;
//Complete all the code which draws the pagination links and also draws all of the returned items as HTML and then returns data
return $response;
}

I hope you guys can help and tell me if I'm doing things in a weird way!

thankyou! Smile
}


Messages In This Thread
Correct understanding of MVC system? - by El Forum - 01-01-2010, 06:46 PM
Correct understanding of MVC system? - by El Forum - 01-01-2010, 11:42 PM
Correct understanding of MVC system? - by El Forum - 01-02-2010, 03:55 AM
Correct understanding of MVC system? - by El Forum - 01-02-2010, 05:38 AM
Correct understanding of MVC system? - by El Forum - 01-02-2010, 05:41 AM
Correct understanding of MVC system? - by El Forum - 01-02-2010, 05:48 AM
Correct understanding of MVC system? - by El Forum - 01-02-2010, 05:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB