#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    56
    Rep Power
    11

    Reverse engineering classes and objects


    I am in the process of migrating a site from one framework to another. In order to do this I am trying to leave the templates alone and write functions they require above them. When I have an object being requested like this:

    PHP Code:
    $this->wt_globals->language_selection(true
    How do I write the class / declare the object to return something? I have tried a few methods but they all fail.
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    This is a little more than vague. What is $this? You're using $this inside a template?

    If that's the case, whatever class you're supposed to be in that $this would reference needs a member variable called $wt_globals, which itself is an object with a member function called language_selection()
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    56
    Rep Power
    11
    Yes, I agree it is a bit vague. $this exists in the old template and I don't have it in my new environment yet - which is what I am trying to achieve. I have tried doing something like this:

    PHP Code:
    class WT_Globals{
        function 
    WT_Globals(){
            
    $this->language_selection();
        }
        
        public function 
    language_selection(){
            return 
    "en";
        }

    But that doesn't work. How should it be written? I guess I need to declare $this somewhere - but I am not sure where or how.

    ps. I should add the above class is what I managed to scrape from the existing code;
    Last edited by keiron77; December 18th, 2012 at 09:37 AM.
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    $this is only valid inside a class. You need something more like:


    PHP Code:
    class WT_Globals
        public function 
    language_selection(){ 
            return 
    "en"
        } 
    }  

    class 
    Whatever_loads_your_template{
      private 
    $wt_globals;

      public function 
    __construct() {
        
    $this->wt_globals = new WT_Globals();
      }

      public function 
    renderTemplate() {
         include(
    'template.whatever.php');
      }

    That way, $this in the template will point to class Whatever_loads_your_template, which has wt_globals.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    56
    Rep Power
    11
    Great, thanks for the answer - that worked a treat.

    I haven't really created classes or objects before - just interrogated other that already exist.
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    This is almost certainly a losing proposition by the way. If the site is small, just rewrite it. Why are you switching frameworks?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    56
    Rep Power
    11
    Our client has a US website and 3 European ones which we look after. They have built their US site in Code Ignighter which, as they look after it internally, isn't a problem for them. The European sites are to be built by us, but maintained by PR companies who need it as friendly as possible. So, we are building their sites in MODx which gives us the open framework to develop anything we want (quickly) but a nice interface, advanced permissions etc. for the contributors. So we don't have a complete disconnect from Code Ignighter my plan is to use their templates, untouched, and pull them into MODx. Because their templates contain variables, functions and objects already I need to recreate these to make it work. This means that if they update a template or create a new one I can just import it for us to use.

IMN logo majestic logo threadwatch logo seochat tools logo