CodeIgniter Forums
Resetting class variables to defaults - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Resetting class variables to defaults (/showthread.php?tid=12489)



Resetting class variables to defaults - El Forum - 10-21-2008

[eluser]Daniel H[/eluser]
I start my models with..

Code:
<?php

class x_model extends Model {
    
    // Table name
    var $table = '';
    
    // Order field name
    var $order_field = array();
    
    // Limit and offset
    var $limit = NULL;
    var $offset = NULL;
    
    // Field names in the database table
    var $id = NULL;
    var $name = NULL;
    // etc...

... and then I have a reset() function that looks like this...

Code:
function reset()
    {
        // Ensure all the variables are listed here
        $this->id = NULL;
        $this->name = NULL;
        // etc...
        
        $this->limit = NULL;
        $this->offset = NULL;
        
        $this->order_field = array();
    }

Instead of listing out all the variables again with their defaults, is there a shorthand which just sets the variables back to their original values?

Many thanks,

Dan.


Resetting class variables to defaults - El Forum - 10-21-2008

[eluser]xwero[/eluser]
try playing around with get_class_vars


Resetting class variables to defaults - El Forum - 10-21-2008

[eluser]Daniel H[/eluser]
Perfect - thanks a lot.