Welcome Guest, Not a member yet? Register   Sign In
About:pagination; Q: Does the config data should reside in a model or in controller?
#1

[eluser]developer10[/eluser]
So, everything is in the topic: where to put $config['some_param'] = 'sth here'; - in model or in controller?

in the moment, i'm trying to pull everything related to pagination to controller, but to no avail. there are stuff (config items)
needed by / working only in the model, since they depend on the data pulled from the query (total rows, etc).

it's a very large query, with if statements, which basically serves for the whole site (several filters/parameters included) so that
i can get needed resultset and only then calculate total rows and initiate pagination.

how to send total rows (and such data) to the controller and be able to use it there (eg, as config item)?
#2

[eluser]developer10[/eluser]
just to refresh
#3

[eluser]markup2go[/eluser]
I always put it in the controller. If you need to do a custom count (as you stated), then define the function the does the counting in your model and call it in your controller.

Code:
$config['total_rows'] = $this->your_model->custom_count_function();
#4

[eluser]developer10[/eluser]
[quote author="markup2go" date="1260243976"]I always put it in the controller. If you need to do a custom count (as you stated), then define the function the does the counting in your model and call it in your controller.

Code:
$config['total_rows'] = $this->your_model->custom_count_function();
[/quote]

is it possible to get a variable from the previous function in my model?
if so, i wont need an extra query (in my custom function). if yes, there's no
way i can avoid the extra query, right?
#5

[eluser]markup2go[/eluser]
I'm not quite sure what you're asking but you can pass variables the usual way.

Code:
$config['total_rows'] = $this->your_model->custom_count_function($someVariable);
#6

[eluser]developer10[/eluser]
[quote author="markup2go" date="1260304649"]I'm not quite sure what you're asking but you can pass variables the usual way.

Code:
$config['total_rows'] = $this->your_model->custom_count_function($someVariable);
[/quote]

here's my model:

Code:
function fetch_all($getDjelatnost, $getGrad, $getSlovo, $getStart, $per_page, $getFid, $getPortfolio)
    {    
        $upit = "    SELECT * FROM _tbl_firme LEFT JOIN tbl_djelatnosti ON _tbl_firme.d_id = tbl_djelatnosti.d_id
                    WHERE ";
            if($getDjelatnost && $getDjelatnost != 'Sve')
                $out = " d_seo = '$getDjelatnost' AND ";
            else $out = "";
                $upit .= $out;
                
            if($getGrad && $getGrad != 'Svi')
                $out = " _f_grad = '$getGrad' AND ";
            else $out = "";
                $upit .= $out;
                
            if($getSlovo)
                $out = " _f_ime LIKE '$getSlovo%' AND ";
            else $out = "";
                $upit .= $out;
                
            if($getFid)
                $out = " f_id = '$getFid' AND ";
            else $out = "";
                $upit .= $out;
                
            if($getPortfolio)
                $out = " _F_KEYWORD = '$getPortfolio' AND ";
            else $out = "";
                $upit .= $out;
                        
        $upit .= " f_vidljivo = 1 ORDER BY f_istaknuto DESC, _f_ime ASC ";
                
            $limited = $upit . " LIMIT ";        
                if($getStart)
                    $out = $getStart;
                else $out = 0;
                    $limited .= $out;
            $limited .= ", " . $per_page;

        $query = $this->db->query($limited);
        
        $numFiltered = $this->db->query($upit);
                
        if($query->num_rows() > 0) {
            $result = $query->result();
        }
        
        return $result;
    }

now i moved my $config['data'] to the controller:

Code:
$config['total_rows'] = $this->Adresar_model->custom();  // (old code) $numFiltered->num_rows();

in my model, below the fetch_all() function, will come custom() function.
is it possible to have the variable $numFiltered from fetch_all() in it, or i have to run the same query in custom() as well, in
order to count the rows, get results, and have its value called from the controller the way you suggested:

Code:
$config['total_rows'] = $this->Adresar_model->custom();




Theme © iAndrew 2016 - Forum software by © MyBB