KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
From what was described before, you could call the __Constructor repeatedly even if you hadn't instantiated yet. (Maybe I misunderstood?!) Yeah, I think you misunderstood. Calling the constructor IS instantiating an object. Whenever the word 'new' is written an object is being instantiated. Now, you don't need to DEFINE a constructor. If you don't define one, PHP will simply invoke the default constructor, which doesn't do anything but tell PHP "Hey, this is an object." You CAN make a constructor private. This is used when you want to deny public/multiple instantiation. It's a critical part of the Singleton pattern and other static classes (Factories).
-
If it is left "Public", can anyone tamper with it? TomTees It can be executed (and will instantiate the object), and it can also be overridden. So you just have to live with it being "public" and hope your constructor doesn't get hacked, huh? :-\ TomTees How would it get hacked?
-
You can still stuff that user object in a session. You may not want to store the entire object that way if your user object is fairly large, however. Also, there's nothing wrong with doing it the 'normal' way. In fact, you could store a user's username and some sort of temporary unique identifier in sessions, then rebuild the user object when necessary from that. That would save you from passing the entire object from page to page.
-
Doesn't matter in either case. EDIT: In JavaScript, brace position does matter. It's always best to keep the opening brace of a function on the same line as its name and argument list in JavaScript.
-
It's a style thing. A lot of coders prepend an underscore to private members to denote that they are private. It improves readability, but has no functional meaning. Yes.
-
Thanks, That worked perfectly Now I'm trying to understand why. I thought an html tag would not work inside php code but obviously it can if its done right. This code builds the HTML of the form's dropdown options. This is a very common use of PHP. Remember how the general HTTP request cycle goes: Request to server -> server points request to proper PHP script based on the address -> script processes request, formulates results, and generates HTML, either by writing it dynamically or using templates -> results sent back to browser -> browser renders page and runs JavaScript (if any is there). PHP - or any server side scripting language, for that matter - would be pretty useless if it couldn't write HTML.
-
I don't recommend Joomla as a substitute for what you're trying to do. I find it to be flawed in several areas. I do think you should look at how it handles templates in its code, just so you can see how a non-CSS only approach could look. In other words, don't use Joomla as your solution. Look at its code to figure out how to do it yourself. Personally, I wouldn't recommend Joomla to anyone, having done some work with it recently.
-
This topic has been moved to Website Critique. http://www.phpfreaks.com/forums/index.php?topic=311075.0
-
This is actually close to the way Joomla does templates. They use PHP files which are mostly HTML. The PHP bits check to see if any modules should be displayed at set positions. You should download Joomla and take a look. It comes with three different templates out of the box. Look at their index.php files.
-
Ridiculous and disgusting, regardless if you're merely trolling or actually mean what you say.
-
The only other way to do it is to make individual PHP template files. include them based on a user's settings. You'll need to make sure you keep your code that handles and processes requests as separate as possible from the code that handles displaying things.
-
Some CSS is hard to do. No denying that. That's one of the reasons I suggested you look up the box model. CSS positioning didn't make any sense to me until I learned that. Positioning and document flow are the two most powerful, and the two most difficult, concepts to grasp with CSS. Once you understand them, the rest is child's play. And, the purpose of the Zen Garden site is to showcase what CSS can do. There's but one HTML file for the demonstration page. All of the differences between the various layouts (images, fonts, positioning) are due to the CSS files. We're suggesting it because: 1. It really is the most efficient way to do it. 2. It's something you need to be comfortable with if you want to do web work for a living. No one is holding a gun to your head. Do what you want. You have nothing to prove to us. But remember that you did come to us for advice. I believe we all gave you the best advice we could. Do what you want with it.
-
!!! CSS is the best way to construct a layout. Why? Because it has a ton of positional attributes and options that allow you to put an element anywhere on the page, regardless of where it was written in the HTML document. If this table was for layout, you shouldn't have been using a table anyway. Tables are for tabular data, not layout. Use divs instead. It's a lot easier that way. Also, don't give up on CSS because you had a bad experience with it. If you're going to be doing any kind of web work professionally, you need to know it and use it. Not doing so is akin to a chef not knowing how to boil water. It is that fundamental. If you're having trouble with CSS positioning, do a Google search for 'CSS box model'.
-
You can fudge multiple inheritance with interfaces. A class can extend only one parent class, but can implement any number of interfaces. It also helps with polymorphism, as interfaces count as a type. This, in turn, allows you to abstract your code, which is what OOP is all about - nice, abstract APIs for use in the client code, where the implementation of the API is handled away from prying eyes.
-
Displaying a price based on drop down selections`
KevinM1 replied to craigtolputt's topic in PHP Coding Help
You're going to have to do a SELECT query that matches everything (pseudo-code) : SELECT price FROM tablename WHERE colours = selected color AND size = selected size AND quantity = selected quantity.... Keep in mind that the price won't magically pop up regardless. PHP can't respond to browser events. So, even if your code is correct, it won't run unless the values are sent to the server and the results are sent back. This is done either by manually submitting the form, or by using JavaScript to write some ajax code. -
It seems like he has a series of constants defined and wants to dynamically choose which one to use based on an external variable.
-
Displaying a price based on drop down selections`
KevinM1 replied to craigtolputt's topic in PHP Coding Help
If different items are going to have different properties (as in, Item1 could come in a different color, or could be double-sided, etc), you'll need to normalize your database to account for these variations. Take a look at this and see if you can apply it to your system before you design yourself into a corner: http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html In short, a database isn't a spreadsheet. Don't treat it like one. -
Eh, it's not as bad as you think. For one, you have to remember that the court TV shows are there for entertainment. While the cases are real, they deliberately pick a lot of the crazy/dumb ones. Also remember that just because you have the right to sue, it doesn't mean you'll be successful. Judges toss out cases all the time. Small claims cases, which is what is shown on TV, is the cesspool of our legal systems. There's no real need for representation, and there's no screening process before they get to a judge. Because of that, it's usually a whole bunch of nonsense.
-
In the States, libel and slander can be sought if the company/person can show that the statements are false and damages were a result of what was written or said. So, saying "I think Mr. Thompson is an asshole" isn't slander. Neither is saying "Mr. Thompson is a known rapist who can only derive sexual pleasure when he chokes or burns himself" unless it can be shown that the statement is false and causes damages to Mr. Thompson or his business (this is where it gets tricky - a tarnished reputation can be considered damages in the eyes of the court, especially if that reputation drives business). In short, insults, criticism, and parody, by themselves, aren't libel/slander. That doesn't mean that it's a good idea to write negative things about others. This is a good point. Even if something isn't slanderous, that won't stop people/companies with deep pockets from attempting to come after you. Even if the case would be thrown out at the first hearing, they'd at least force you to hire representation and go through all the pomp and circumstance. And, naturally, they'd try to delay the process as much as possible in order to make your legal costs go up as much as possible. Still, a lot of companies won't waste their time. People bitch about companies all the time. So long as it doesn't potentially impact their bottom line by a significant amount or causes an inordinate amount of embarrassment, I doubt they'd care.
-
There is that, too (can't believe I missed it ).
-
The only thing that sticks out to me is the first line. You create a new instance of System without assigning it to anything. That particular instance is therefore inaccessible. Not really. In PHP you can create public properties on-the-fly by assigning a value to them. That's a feature I always hated. I like my objects to have concrete interfaces.
-
Ah that makes sense! So my 2nd example is stating the $var could be an array, right? The second example says that if no argument is passed to the method, $var will be an empty array by default. Otherwise, it will be whatever you passed to the method.
-
Well, mysql_real_escape_string isn't an issue here since these ids aren't strings. Your other point is correct, however. If left in the wild like this, anyone would be able to delete these records simply by sending integers to the script. That's why we have administration areas - dangerous bits of script like this are hidden behind some form of access control to keep the barbarians out.
-
I'm doing some small-scale Joomla work for a client. Most of it is installing and configuring extensions, but it looks like I'll have to write some code to tweak some stuff. Here's my problem: My client is using DOCman to manage, well, his documents. These documents are available to two different groups of members - normal community members, and partners. DOCman's permissions do the job in hiding the right files from the right people, but he wants to hide the actual menu navigation link to the partners' section if the user isn't a member of the DOCman partner user group. This functionality is not present in DOCman. I'm not familiar with Joomla or DOCman at all, from a coding perspective, so I'm not entirely sure where to start. Ideally, I'd simply access the DOCman User object for the current user, check what group they belong to, and hide the menu item from there, but I'm not sure if it's possible, nor how to do it if it is. I just need a nudge in the right direction so I don't waste a bunch of time looking at the wrong files. Any ideas? Joomla 1.5.20 DOCman 1.5.8
-
What do the error messages actually say? Also, post your existing code.