Welcome Guest, Not a member yet? Register   Sign In
Check My Code
#1

[eluser]ChazUK[/eluser]
Basically just wondering if I am doing this write.

The Model is just for grabbing data, no validation? no checking for num rows, just a simple query to a database, rss, file, datasource and then manipulate, check and validate the data in the controller?

Code:
<?php

class Statistics_model extends Model {

    function Statistics_model()
    {
        parent::Model();
    }
    
    
    function get_master_stats($start_date = NULL, $end_date = NULL) {
        
        if($start_date === NULL) $start_date = mktime(0, 0, 0, date("n"), 1, date("Y"));
        if($end_date === NULL) $end_date = mktime(0, 0, 0, date("n"), date("t"), date("Y"));
        
        $sql = "SELECT nucleus.stats_data.*
                FROM nucleus.stats_data
                WHERE nucleus.stats_data.stat_date BETWEEN ? AND ?;";
        $query = $this->db->query($sql, array($start_date, $end_date));
        return $query;
        
    }
    

}

/* End of file statistics.php */
/* Location: ./system/application/models/statistics.php */

Does this look ok?
#2

[eluser]BrianDHall[/eluser]
[quote author="ChazUK" date="1255114613"]Basically just wondering if I am doing this write.

The Model is just for grabbing data, no validation? no checking for num rows, just a simple query to a database, rss, file, datasource and then manipulate, check and validate the data in the controller?
[/quote]

Actually you are restricting your ability to use a model too much, and requiring your controller to be too...controlling Wink

Models can handle validation, manipulate data, even interact with other models directly (like a Billing model might need to interact with a Payments model and an Orders model). Some people use models as nothing more than a "data access interface" - but when you think about it, this means a model is little more than lightweight database abstraction. For 1/3rd of the whole MVC equation this seems like asking too little of one thing and too much of another.

In your example, there is no reason your Statistics model couldn't validate input/output, have functions for returning advanced statistical data that requires various calculations and manipulations of the data.

Models are the guardians of your applications 'state', or data. As such they needn't be dumb - they can check new data requested for saving to ensure it is valid and coherent, create 'meta-data' and perform computations and operations...basically any such task that logically is a part of the job for a guardian of data.




Theme © iAndrew 2016 - Forum software by © MyBB