Welcome Guest, Not a member yet? Register   Sign In
Resetting class variables to defaults
#1

[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.
#2

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

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




Theme © iAndrew 2016 - Forum software by © MyBB