Jump to content

keeB

Staff Alumni
  • Posts

    1,075
  • Joined

  • Last visited

Everything posted by keeB

  1. http://www.chiptune.com/
  2. Did I not share with you the best practice I am aware of?
  3. Should be a foreign key on uid to user.id. Other than that, it looks fine.
  4. No they don't. Read this: http://en.wikipedia.org/wiki/Relational_Database
  5. Yeah but it's a vulnerability for XSS. Imagine someone constructs a URL with a malicious script that steals your cookie for your site and emails it to them. Bam, now said person has access.
  6. I think if you want to have a quality conversation/debate, taking the time to spell things properly and show just a tiny bit of effort. Yes, I'm talking to you nadeemshafi9.
  7. You could think of it as an alternative to the $_SESSION super global.
  8. I think it really depends on the amount of complexity you would like to give. I think you should start out by being strict and only loosen restrictions if they're causing you to write shitty code. I'm trying to think of an appropriate way to explain Context. I have seen it used in a few enterprise OO applications but I can't give examples directly from them. Basically what a context is is a specialized registry for the current user. What you'd find in there are methods like: getUser() # return user model object with reference to current logged in user or 'anonymous' user getCurrentPage() # returns the current page Basically anything that can be more specialized than your registry class. I'm sorry, I know that's not really helpful.
  9. I think you need to supply a common interface for plugins to be loaded in your controller. If I understand the style you're looking for, what you're trying to do is have a plugin that would be prototyped as follows: <?php interface Plugin { public function getAuthor(); public function getVersion(); public function setContext(Context $ctx); public function draw(Template $tpl); //draw specific template public function handleSubmit(InputParameterList $params) // params would be sanitized so it doesn't have to. } class NavigationPlugin implements Plugin { private $current_location; private $children = null; private $context = null; public function getAuthor() {return "I am the author";} public function getVersion() {return 1.0;} public function setContext($ctx) { $this->context = $ctx; } public function draw(Template $tpl) { //augment, whatever $user = $this->context->getUser(); echo "Welcome, $user"; $tpl->render(); } public function handleSubmit(InputParameterList $params) { if ($this->context == null) throw new ContextNotInitializedException(); $this->children = $this->context->getPage($params->get('page') /* returns Page object or whatever */)->getChildPages(); foreach ($this->children as $child) { echo '<a href="' . $child->getURL() . '">' . $child->getName() . '</a>'; } } } ?> I think this handled the cases you wanted to handle, right? What I have introduced which you may not have is a context. This would be kind of like your Registry class, but with more.. context
  10. I'd take a look at how Drupal does it. In the meantime, I have to go to the pediatrician. Back in 2 hours
  11. Why not allow the packaging of Model objects with views? Pseudo directory structure / <- document root lib/ <- where your framework is config/ <- configuration options plugins/ pluginA/ model/ AboutUsModel.class.php view/ AboutUsView.tpl class PluginHelper { public function load($name) { // load and register (with controller) all files in plugins/$name/model and plugins/$name/view } } The benefit of this is, you would build your site with a series of 'Plugins' which are completely abstracted away from your framework. If you have a blog plugin, you should be able to plug it in with minimal effort since you have the Model and View dialed.
  12. I know in Java, localization usually comes in 'properties' files. Here's a prototype in PHP: Template <p> There was an error ${my.error.string} </p> errors.en_us.properties my.error.string=The command ${opname} is not recognized. Please try again. operation.unavailable.error=The command ${opname} is temporarily unavailable. Please try later. errors.sp_mx.properties my.error.string=Desconocido Operacion ${opname}. operation.unavailable.error=Operacion ${opname} indisponible. Render <?php $user = UserDao::getUser($_SESSION['username']); // populate the user model object try { $a = Localization::Load($user->getLocale()) //load the proper localization file } catch (LocaleNotFoundException) { $a = Localization::Load(Localization.DEFAULT); } $p = new Template("mytemplate.tpl"); $p->render($a); ?>
  13. I was with ya until the 3rd paragraph. It sounds like you have a good MVC design going. If I understand correctly, what you're trying to add in to the mix is a way to create the Model/View without having to actually write the Model/View? Or, am I missing the intention?
  14. use_potion should return an int, i.e use_potion() returns 10 and hp_up should accept an int.
  15. I understand I am explaining how I'd do it to get you thinking about improvements in the future. You posted while I was posting, I like this idea the most: <?php $char->hp_up(use_potion($itemID)); ?>
  16. I think you should have a generic method in your char class called use() Prototyped as follows: <?php class EntityDao { public static function getCharacterById($id) { //creates a inventory object //creates a weapon object //creates a armor object //creates a template user, with user->setHp, user->setMana; // calls user->setInventory($InventoryObject) // calls user->setWeapon($WeaponObject) return user } } // User model object abstract class Entity { private $id; private $totalhp; private $currhp; private $mana; private $inventory; private $weapon; private $armor public static function addHp($num) { //should be defined some other way, but this is for the sake of simplicity return array('hp' => $num); } abstract function use(GameObject $obj) {} } class PlayableCharacter extends Entity { public function use(GameObject $obj) { $vals = $obj->use(); // $vals should be like an AttributeModifier object or something like that, but i am lazy $this->setHp($vals['hp']); $this->setMana($vals['mana']); $this->setSomeOtherModifier($vals['some_bonus']); } } interface GameObject { // define all things game objects must do public function use(); } public class MinorPotion implements GameObject { public function use() { return Entity::addHp(20); } } public class MajorPotion implements GameObject { public function use() { return Entity::addHp(40); } } ////////////// game code //////////////////// $mychar = EntityDao::getCharacterById($id) $majorPotion = MajorPotion(); $mychar->use($majorPotion); ?>
  17. Can you give me an example of what type of plugin you'd be looking to develop?
  18. http://nick.stinemates.org/wordpress/?p=26 Questions and comments are appreciated.
  19. I'll take a performance hit any day over having to go back to procedural garbage, tyvm I don't think this is a thread for that, though.
  20. Why not? I mean, you never know what interesting ways people will come up with to circumvent your code, so wouldn't having a "catch-all" or "catch-all-the-rest" type thing be the best thing you can have for that? I do. If my if statement returns something, else will never get executed if the condition is true, so.. 'else' is really what happens If my if statement did not execute Generally, though, I try to keep conditional logic to a minimum. I like to keep my code as straight forward as possible.
  21. My style <?php if(($hours < 24) && ($minutes < 60) && ($seconds < 60)) return true; return false ?> As for multiline things (I am not a fan of else): <?php class MyClass { private $foo = null; public function __construct() { $this->foo = "constructed"; } public function getFoo() { if ($this->foo != null) return foo; // handle the 'else' statement here. } } ?>
  22. I was trying to come up with a witty reply to this post, but quoting it is hilarious enough.
  23. Whatever makes sense to you -- go for it. What makes sense to me is to break everything I can up in to very small pieces of responsibility. What this grants me is to make sure every little piece does it's job -- and does it well (aka, the first step to encapsulation.) If you give something too much responsibility, just like in real life, there's some trade off's. Programming/design IS a list of trade off's, and since you're still a beginner they won't be so apparent. Fact is, with your current design you're more than able to finish what you've set to accomplish. I think that's something noteworthy. So go for it! And let us help if needed along the way.
  24. ^^ Agree with above. Redbull gave some very great advice. You should understand it before saying you've lost interest.
  25. create table person ( userid int not null ); create table poll ( userid int references user(userid,; -- creates foreign key on user.userid other_columns text ); Load the poll, iterate through userId's. If any match current user's id, display error.
×
×
  • 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.