Jump to content

KevinM1

Moderators
  • Posts

    5,222
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by KevinM1

  1. ? So... it's doing what you want, but that's not what it's supposed to do?
  2. You need to pass $connection into the getUserGroups() function, like you did with $id.
  3. Belated
  4. The problem with what you're doing is that, in addition to your changes being irregular and useless, you're making your code harder to read. You're not gaining anything but a few keystrokes, and that's at the expense of clarity.
  5. Employers really don't care about the pieces of paper potential entry level employees wave in front of them. They're more concerned with: A. What the potential employees do know B. If they're teachable
  6. They're not calling set_name() in the get_name() method because $this->name is initially set by the constructor. In other words, by the time a Person object exists, $this->name will already have a value, which would be available for get_name() to use. That tutorial is kinda shitty, by the way. Hardly anyone uses the 'var' keyword in classes any more (it's a throwback to PHP 4, and best forgotten), and the 'var' keyword is not necessary to make a member public. A data member without any access modifier will default to public, too. The tutorial is also pretty poorly written. That's because you've only looked at tutorial syntax. OOP is not simply wrapping functions in a class and calling it a day. If that's all it was, it wouldn't be used. No, OOP is about creating small, discrete blocks of abstracted functionality that can be plugged into a variety of different systems in a variety of different ways. Admittedly, functions have some of that, too (which makes sense, since OOP generally sprang up from procedural programming), but they don't address the entire picture. Functions model a process - literally "Take these arguments and do something with them". Objects represent things. They are their own data types, and are used to build structures in code. Online tutorials are really one of the worst ways to try to learn OOP. They tend to begin and end with syntax, and never go into the why, which leads to the inevitable question "So... they just group functions together?" Which is completely the wrong way to look at OOP.
  7. @HDFilmMaker2112 - remember that there's a difference between a function definition and a function invocation. Code like the following: <?php function example() { // code // code // code } ?> Only defines functionality. It doesn't actually run until you tell it to: <?php example(); ?> The same thing applies to classes and their methods. Defining a method isn't the same as invoking it. It's not an OO thing, but rather PHP 101. If you're uncomfortable with how functions and scope work, you really shouldn't be trying OO at all.
  8. Not much to say. You took a mediocre theme, changed the font, and... that's about it. The theme itself, like Zulfadly said above, is too narrow/cramped for the content. For me (Firefox 13.1), the slide show doesn't work.
  9. Apologies for leaving the ?> off at the end of my first example. That was definitely not intentional. I think you're over thinking it. <?php <--- enters PHP mode ?> <--- leaves PHP mode { <--- starts a PHP code block } <--- ends a PHP code block That's it. As far as books go, I'm not sure what would be good for an absolute beginner. I started with an earlier edition of Larry Ullman's PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide. It's written in a very easy to understand style, but my edition didn't really dive into best practices. If that doesn't work for you, you can always try the online manual: http://php.net/manual/en/index.php Start at the language reference and work your way down.
  10. <?php and ?> are the opening and closing tags (respectively) for PHP itself. However, you need to take into account braces ({ and }) within your PHP code, as they denote code blocks. Example: <?php if($x == true) { // note the brace // code // code // code } // <-- the closing brace ends the code that is executed if the if-conditional is true When you mix PHP and HTML, you need to be aware of both the PHP tags themselves and whatever brace pairs you may have. <?php // code // code if(/* something */) { // opening brace ?> <-- end of PHP mode, but the rest of the code is STILL taking place within the code block started by the brace above <html> <!-- blah blah blah --> <?php } // closing brace, which closes the block - ALWAYS match braces ?> Blocks are formed by loops, conditionals, and function definitions. All that said, I strongly urge you to think along different lines when you write your PHP. It's usually not a good idea to jump between PHP and HTML a lot in your code. Why? Maintainability, for one. Do you really want to spend time hunting for closing braces within PHP tags, which themselves are nested in HTML? There's also request handling to consider. Well-formed PHP apps look like this: PHP code to process requests, handle data, talk to the DB, etc. | | | V All values that need to be displayed are stored in variables | | | V Jump out of PHP into HTML when ALL data processing is completed | | | V Pure HTML, with the exception of PHP code necessary to display values. That code should NOT be more complicated than: <?php echo $value; ?> Or <?php while(/* some condition */) { echo $value; } ?> Or <?php if(/* some condition */) { echo $value; } else { echo $otherValue; } ?> That may sound overly restrictive, but it's really the best way to go. It ensures that both your PHP and HTML are clean and easy to read, and will allow you to avoid the popular "Headers already sent" error.
  11. What does "does not work" mean? Error message? Data not being saved?
  12. This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=361307.0
  13. - They overload their servers, resulting in terrible performance - Their customer support sucks - Their website is just horrendous as far as usability is concerned - The control panel they use is just terrible... it sometimes takes a long time for simple changes to take effect and, again, terrible usability That was my experience as well. Yeah, I've been trying to find a good domain provider, too. Usually I just pay the extra $10+ when I purchase hosting, but I like the idea of being able to completely change hosting without sacrificing my domains. I've heard good things about hover.com. They start at $15, though, which seems a bit pricey.
  14. My definition of a model is a class / function that handles data. A model should represent data. Like a user. Or a blog post. Or a store item. --- I hesitate to write this as it may confuse you. There's actually two kinds of models: Your honest-to-goodness models which represent your site's business entities. They interact with one another behind the scenes. View/edit models, which are simple DTOs that are used as a proxy to the data that's in the 'real' models in order to narrow down the model data into manageable bits in order to render their data to the screen, or to allow users to edit what's in there. Now, separate view/edit models are not a requirement. They're not considered part of the MVC pattern, really, but they are used. A lot of times, you won't need them. If your 'real' models are simple, there's nothing wrong with using them directly. View/edit models are just a way to keep the I/O of models loosely coupled to the 'real' models and streamlined. --- And jesi is right - the MVC convention is that controller actions and their views should be related by name, but models can have any name they want/need. I should have mentioned that earlier. So, UserModel, BlogPostModel, StoreItemModel all make sense.
  15. You don't have to follow that naming convention. The term 'convention over configuration' is used a lot, which means that 3rd party frameworks will automatically know how to wire up and integrate various classes and other content files if they adhere to the standard convention. You can bypass that convention and create your own, but that generally requires tinkering with the plumbing underneath. The convention itself is largely similar between frameworks because: 1. It works. 2. It allows someone familiar with one framework to be familiar with another. That's why it's a convention. That said, if you're home-rolling your own framework, you can decide how you want to do it. You'll just have an unconventional project.
  16. Just want to chime in and say that CPD has the right of it. Inbound validation usually happens during or after data binding, when you have a model in hand and are trying to stuff new/edited data in it. Inbound sanitation usually happens at the DB layer, generally by an ORM using PDO, which will automatically escape the data. Outbound sanitation generally happens in the view, with a view helper that automatically runs dynamic output through htmlentities. This is pretty much the de facto arrangement. I know that Symfony2 + Doctrine uses it, .NET MVC, likely Rails (since .NET MVC copied borrowed from Rails) and Django, etc.
  17. I usually use http://www.icdsoft.com/hosting.php They're good for small sites, which is usually what I deal with.
  18. Shared or dedicated hosting is fine. That's how it's usually done. Just don't use GoDaddy. They suck. There are far better, more robust, easy to use choices available for the same low cost, if not cheaper.
  19. Ah, my mistake. I thought you said Zend Framework, not Zend Studio. That said, PHP has built-in autoload capabilities. __autoload is the classic variant, while spl_autoload_register is the more modern version. Both work well. When writing OO code, you should never need to write include statements for your classes.
  20. Why are you including files manually? Zend Framework should have an autoloader of some kind.
  21. But I still do not see how "TRUE" can be logically equal to "999" ?! (This I can see... TRUE==1) True is logically equal to all non-zero values. 23.987. 999. "Hello". All of those will be equal to true.
  22. NetBeans is simply showing you the integer value of true, which is 1. It's not actually the number 1 in this case, since you set $preview to logical true. It's just the numerical representation of true. Why is true represented as a 1? Think binary. 1 == on/true, 0 == off/false. In most modern programming languages, any non-zero value that can be converted to an integer will be true. So, True == 999 will always result in true. FWIW, this is boolean logic 101. One of those things you should learn if you're going to use if/else statements.
  23. Please, follow the advice I gave in the 2nd paragraph. You're flailing blindly at your code due to frustration. You can alleviate that frustration by learning how things actually work. Making incremental changes without knowing what you're doing in the hope of stumbling on the magic solution is asinine. PHP.net explains abstract classes and methods, as well as interfaces. Go there, take your time to go through the examples, and try again.
  24. Is that what you want? Not trying to be flippant here. Declaring a class as abstract would change the way it's used. You shouldn't be looking for a quick fix just to get rid of an error. Before you go any further you should read up on abstract classes and interfaces. They're basic OO constructs that you need to understand before attempting to use them.
  25. When you create an interface, any class that implements it must do so exactly. The method in question is defined to take a User object as its first argument in the interface, but in the class that implements it you pass in an integer. See the problem? Either get rid of the type hint in the interface, or pass in a User object in the class method.
×
×
  • 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.