Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts

    A flexible GETTER Class.

    NOTE: I will be updating this periodically to make it better. I am going to expand on it and make it a post and get class. The current version is 1.0
    Here is a flexible GETTER class if anyone is interested. I am always open to improving it. Its pretty simple. Suggestions welcome.

    Getter.php
    PHP Code:
    <?php
    /* 
    Author: Chris Hickingbottom
    Date: 3/16/2012
    Description: This class is designed to flexibly grab the variables in a url. 
    Version: 1.0
    */
     
    class Getter {
     
        private 
    $getters = array();
     
        function 
    __construct($gets) {
            foreach (
    $gets as $get=>$default) {
                
    $value = !empty($_GET[$get]) ? $_GET[$get] : $default;
                
    $this->getters[$get] = $value;
            }
        }
     
        public function 
    getGetter($get) {
            return 
    $this->getters[$get];
        }
     
    }
    Example.php
    PHP Code:
     
    <?php
    require_once('getter.php'); // include the file. 
     
     // set the variables you are searching for in an array 
     // the key being the name of the variable and the other being the default value if it is not set
    $gets = array('firstName'=>false'lastName'=>false);
    $getter = new Getter($gets); // initialize the class using the array of variables that you want
    $carType=$getter->getGetter('carType'); // grab the specific infomation you want
    $carModel=$getter->getGetter('carModel'); // grab the specific information you want
     
    if(!$carType) {
        echo 
    'False';    
    } else {
        echo 
    $carType;
    }
    echo 
    "<br />";
    if(!
    $carModel) {
        echo 
    'False';    
    } else { 
        echo 
    $carModel;
    }
    ?>
    Last edited by Chris Hick; 03-18-2012 at 09:20 PM.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •