keeps21 Posted October 19, 2008 Share Posted October 19, 2008 Hi I'm trying to get my head around OOP and MVC. I'm wondering whether I have it right with the following code - also attached as a zip file. model.php <?php class Student { /* These are some of the properties */ var $Name; var $Gender; var $GradeLevel; var $Schedule; /* Constructor. Called as soon as we create a student */ function Student($studentName, $studentGender) { $this->Name = $studentName; $this->Gender = $studentGender; } function goToClass() { } function rideTheBus($busNumber) { $statement = $this->Name . " rides bus number " . $busNumber; return $statement; } function skipSchool() { } function changeGender() { if ($this->Gender == "Female") { $this->Gender = "Male"; } else { $this->Gender = "Female"; } } } ?> view.php <?php include "model.php"; include "control.php"; print $a_student->Gender; print "<br>"; print $b_student->Gender; print "<br>"; print $c_student->Gender . " " . $c_student->Name; print $a_student->rideTheBus("65"); print $c_student->Gender; // this will print "Male" now... ?> control.php <?php $a_student = new Student("John","Male"); $b_student = new Student("Mary","Female"); $c_student = new Student("Larry","Female"); $c_student->changeGender(); ?> Any advice would be greatly appreciated. Thanks. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/129094-oop-and-mvc/ Share on other sites More sharing options...
Liquid Fire Posted October 19, 2008 Share Posted October 19, 2008 At a very basic level, that is the MVC pattern, generally controllers themselves are classes too. Quote Link to comment https://forums.phpfreaks.com/topic/129094-oop-and-mvc/#findComment-669227 Share on other sites More sharing options...
DarkWater Posted October 19, 2008 Share Posted October 19, 2008 1) Don't use PHP4. 2) It doesn't seem like MVC really...you'd usually call a specific controller method to handle certain models and views... >_> Quote Link to comment https://forums.phpfreaks.com/topic/129094-oop-and-mvc/#findComment-669249 Share on other sites More sharing options...
keeps21 Posted October 19, 2008 Author Share Posted October 19, 2008 1) Don't use PHP4. You've lost me with this? I'm running 5.2.5. 2) It doesn't seem like MVC really...you'd usually call a specific controller method to handle certain models and views... >_> Is there an example you could give me for this to explain what you mean? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/129094-oop-and-mvc/#findComment-669374 Share on other sites More sharing options...
DarkWater Posted October 19, 2008 Share Posted October 19, 2008 I meant "Don't use PHP4 OOP syntax". It's horribly deprecated. Look up PHP5 OOP syntax. And check out how CakePHP and Zend Framework do their routing calls. They use call_user_func_array() to call certain controller methods based on what's being asked for by the client. Quote Link to comment https://forums.phpfreaks.com/topic/129094-oop-and-mvc/#findComment-669393 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.