#1
  1. No Profile Picture
    http://stealthwd.ca
    Devshed Novice (500 - 999 posts)

    Join Date
    Dec 2005
    Posts
    691
    Rep Power
    200

    Function called before all class functions.


    Hey everyone. In the CMS I've built I have an abstract class that is the parent to all the classes of the modules of my cms. So for example I have functions like this in it...

    Code:
    		function getAllRecords(){
    	
    			
    			parent::openConn();
    						
    			$result = mysql_query("SELECT * FROM " . $this->getTable());
    
    			parent::closeConn();
    											
    			if($this->ajax == true){
    				echo $this->phpMySQLtoJavascriptArray($result);
    			}
    			else{
    				return $result;
    			}	
    		}
    		
    		function getRecordByID($recordID){
    		
    			parent::openConn();
    						
    			$result = mysql_query("SELECT * FROM " . $this->getTable() . " WHERE " . $this->getPriKey() . " = '" . mysql_real_escape_string($recordID) . "'");
    			
    			parent::closeConn();
    											
    			return $result;
    			
    		}

    What I want to do now is add an extra level of security. I want all the functions in the abstract class to run function checkSecurityLevel at the begining, or before they're called or something along those lines. I was probably, and will probably just call that function manually first thing in all the functions, but was wondering if there was a better way to do this using some technique I'm unaware of.

    To sum it up, I want function checkSecurityLevel top be called prior to any function in my abstract doing anything.

    Thanks!
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,248
    Rep Power
    9400
    The best way would be to put a call to it manually in each function.

    Comments on this post

    • Dameon51 agrees
  4. #3
  5. No Profile Picture
    http://stealthwd.ca
    Devshed Novice (500 - 999 posts)

    Join Date
    Dec 2005
    Posts
    691
    Rep Power
    200
    Originally Posted by requinix
    The best way would be to put a call to it manually in each function.
    Cool man, thanks. I thought I would have to do it that way, but its always good to get second opinions too.

IMN logo majestic logo threadwatch logo seochat tools logo