Jump to content

TomTees

Members
  • Posts

    187
  • Joined

  • Last visited

    Never

Everything posted by TomTees

  1. What does this code do? public function render() { $this->set('users', $this->model->findAll()); } TomTees
  2. What is the relationship between an HTML form and the "View" in the MVC model? Is the View a class linked to the Form? Would someone please help me better understand this TomTees
  3. I don't believe that will work. Anyone else? What about answer to my other questions as well? Thanks, TomTees
  4. I was given the snippet below and am trying to figure some things out... abstract class FormCollection{ protected $fields = $_POST; protected $validator; protected function __construct($validator){ $this->validator = $validator; } // and so on... } class RegistrationForm extends FormCollection{ private $formInputs = array(); // and so on... } Questions: ----------------- 1.) If I instantiate the concrete class, RegistrationForm, like this... $form = new RegistrationForm(new Validator()); What does that do to the abstract class, FormCollection? Is it getting instantiated too? 2.) I thought you could NOT instantiate an abstract class like FormCollection? 3.) If you can't, then why is there a constructor in the abstract class like FormCollection? 4.) This code seems wrong... protected $fields = $_POST; I was told by somene that PHP doesn't allow you to assign values to a class method at compile time unless the values come from a constant?! TomTees
  5. Netbeans says this is a syntax error... $this->formValues = $_POST; And if I run my code (form) then I get this... TomTees
  6. How do I assign the entire $_POST array to a varible? This code isn't working... <?php echo 'FormHandler'; class FormHandler{ private $formValues = array(); $this->formValues = $_POST; } ?> TomTees
  7. Can someone help me understand this code... Questions: ---------------- 1.) If an Abstract Class cannot be instantiated, then how can there be Properties? 2.) I guess $fields is supposed to be an array? How do I know that? Isn't there a way to do "type hinting" or whatever? 3.) What data-type is $validator? TomTees
  8. Kind of like gravity and Wile-E-Coyote?! Are Namespaces used much? Do they provide much value? TomTees
  9. Ah, said better than me! Yes, good link! Thanks, TomTees P.S. How do you mark something "Solved"??
  10. It only effects non-namespaced classes. What does that mean in English?! TomTees
  11. So -> is to access instance properties and methods and :: is to access static properties and methods? TomTees
  12. What do 2 colons together ( mean?? TomTees
  13. I guess that means if I wanted to use the old-style to mimic Java it would backfire after v5.3.3, right? TomTees
  14. I know this is a PHP site, but is it true that in Java the constructor has the same name as the class name? I went to the PHP.net manual and it has a similar set up. Is that correct? I thought there was some other convention that differed from Java? TomTees
  15. Thanks for the comments. Okay, but you could view an Abstract Class as a "contract" of sorts as well, because it promises that you will always have certain Properties and/or Methods, right? The difference being - as I understand it - that an Abstract Class would usually not only provide the "contract" of certain Properties and Methods, but the implementation as well (which Interfaces cannot do). Maybe this is an example... TomTees
  16. >> 2.) When you have an Abstract Class with Properties & Methods, are you required to use all of the listed >> Properties & Methods similar to how an Interface works? > > 2) Only if they are declared abstract, everything else is inherited. So if a Property or Method is not declared "abstract" then you do not have to implement it with an Abstract Class? >> 3.) What is the intent of using Abstract Classes vs. Interfaces? > > 3) Only an abstract class allows you to define a body for a method (for example define an interface method) So an Interface is just a "contract" that you will implement the listed Methods, but an Abstract Class *can* goes farther and actually spell out what any declared Abstract Methods will entail? TomTees
  17. Would someone help me out with Abstract Classes and Interfaces... Some questions... 1.) When you have an Interface with Methods, then any Concrete Class that "implements" said Interface must include all of the listed Methods, correct? 2.) When you have an Abstract Class with Properties & Methods, are you required to use all of the listed Properties & Methods similar to how an Interface works? 3.) What is the intent of using Abstract Classes vs. Interfaces? TomTees
  18. Okay, I follow what you are saying now. Yeah, if you want to become an expert on CSS Forms, that is one of the better articles/tutorials out there. That and it also takes in to account Accessibility which is always good! Happy reading, TomTees
  19. The <em> could be left in for semantic reasons, although they were more useful when styling left aligned labels and hugging asterisk images. Anyways, the article explains everything. TomTees
  20. My code actually needs to be updated since I changed the label alignment, but when the labels were left aligned, I need <em>. See this article about 3/4 the way down... http://articles.sitepoint.com/print/fancy-form-design-css I have no clue what you are saying?! I used a text field to gather the password. Why would you use anything else?! TomTees
  21. Because it seems to me that the author of a PHP book I read said it was and so he always used "pass1" and "pass2" on his forms. (Or so I recall?!) TomTees
  22. The <em> is a CSS usability trick that I learned. TomTees
  23. Is 'password' a protected/resevred term in either PHP or HTML? Is this code valid... TomTees
  24. Sorry, I have been traveling and couldn't find the old thread plus I forgot that you said that. I was just trying to reduce procedural code. That's why I'm here for help! Because I obviously don't understand OOP very well yet. (And all of those textbook 'Hello World' examples are useless.) You lost me here. The first thing I am trying to build is a simple Registration page/module. The person is requesting anything. Okay, so let me dive a little deeper and explain what I am trying to do... I am trying to build an e-commerce site and I want to do it using PHP and OOP. (And no, I do NOT want to use a framework at this point. This topic has been beaten to death by many a kind soul.) My whole life I've been stuck doing procedural code and I've never been able to go from DuckSimulation and HelloWorld class examples in textbooks to something real-world like an e-commerce site. While I don't know OOP, it is painfully obvious that most examples and people online don't really understand OOA, OOD, OOP and Design Patterns because there is a lot of dumping procedural code into classes - as you mentioned above - for the sake of it and really no planning into abstracting real-world things into logical OO designs. It is not my goal to become a Gang-of-Four Fellow the first go 'round, however, I would like to write *reasonably* well laid out classes. So... My first goal is to build a simple User Registration module. The flow would go like this... - User enters Email - User re-enters Email - User enters Password - User re-enters Password - User enters Name - User submits Registration Form - System ensures valid Email - System ensures Emails match - System ensures valid Password - System ensures Passwords match - System ensures valid Name - System ensures Email is unique - System create new User account/record - System notifies User of outcome ...from here the User would need to Log-In which leads to my next mini-project ---> build a Log-In module (using OOP)! I will need a "User" class and after discussing this topic with several people I trust, having a "RegistrationService" class seems wise. I just figured that taking the User's form values and placing them in a "FormHandler" object which could inturn be passed to my "RegistrationService" object would be a nice OOP way to do things?! Hope that help describe more of what I'm trying to do? Sincerely, TomTees
  25. Sorry if I asked this before in some variant, but I had to put my OOP studies aside for a few weeks, so here I go again?! I am trying to learn OOP and would like to take the data submitted in a form and put it into an object so I can pass that to other objects and do stuff with said data in OOP terms. My *limited* understanding of things so far is this... If I have form "registration.php", when the user clicks 'Submit' then data from the form gets populated immediately in the $_POST array and control would go to the action page... I would like to take - email - password - name into a generic object called FormHandler. (Maybe this isn't how the OOP gurus would do it, but hmor me as I am trying to learn elementary OOP, and use something that works for me.) So how would I go about doing that? All I can think is to have an action page called "form_handler.php" and when the user submits the form in "registration.php" then "form_handler.php" would instantiate FormHandler which would assign the $_POST array into either its own array or into individual variables. Maybe something like... class FormHandler{ private $someArray(); // OR private $email; private $password; private $name; function __construct() { $this->someArray = $_POST(); // OR $this->email = $_POST['email']; $this->password = $_POST['password']; $this->name = $_POST['name']; } } Feel free to tell me what you think of my code and idea, and please be nice because I have never written any OOP before and it is hard to break my old procedural ways! :-\ TomTees
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.