From: Michael C. <mi...@ca...> - 2002-05-27 00:08:21
|
Simply put, you can't include files from with PHP classes. You can include them before the class or afterwards but not within it. Something I'm moving to is Smalltalks MVC model. Model, View, Control. With models being the actual data operations created into a class (class listuser_model would get/set data but not create views of it). Control would be like the buttons on forms or links, but even it's related to how index.php's switch'ing. Lastly is View or pretty much the user interface such as class listuser which extends listuser_model by calling the get/set methods from within their own methods. Through the MVC methodology you can abstract many of those common functions that you use from module to module while only worrying about the view. MVC is just one way to allow abstraction of how you do something and how you display it. Hopefully the following will help explain what I'm talking about. I'll be releasing a sales lead module here shortly built upon this methodology. Thank goodness for OOD courses... Now, I just can't wait for polymorphism in PHP... // listuser_model.php // model has data get/set operations, but not UI stuff class listuser_model { var $name function getName() { return $this->name; } function setName($newName) { $this->name = $newName; } } // listuser.php // view is the UI stuff class listuser extends listuser_model { function viewName () { $box_title = 'Some Name'; $box_content = $this->getName(); $this->display($box_title, $box_content); } function viewForm () { $box_title = 'Change Name'; $box_content = " <form method='post' action='mod.php'> <input type='hidden' name='mod' value='listuser' /> <input type='hidden' name='op' value='changeName' /> <input type='text' name='name' value='$this->getName()' /><br /> <input type='submit' name='submit' value='Submit' /> <input type='reset' name='reset' value='Reset' /> </form> "; $this->display($box_title, $box_content); } function display($title, $contents) { thememainbox($title, $contents); } } // index.php // one way to think of controller include_once('listuser.php'); include_once('listuser_model.php'); $L = new listuser(); switch($op) { case 'changeName': $L->setName($_POST['name']); break; default: $L->viewName(); $L->viewForm(); } Cheers, Michael ----- Principal, Cannon BOSE Business Operation * Software Engineering mi...@ca... www.cannonbose.com 1-206-351-0159 |