KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
For more info, Intro to Database Normalization: http://mikehillyer.com/articles/an-introduction-to-database-normalization/
-
Just a slight digression: Don't use all capital letters for a subject title. It reads as you screaming/yelling at people. I've changed it to a more polite normal case title.
-
Autoload is pretty much what it's called - it allows you to automatically load the file that contains a class definition whenever a class is referenced (like, whenever you try to write new Class(); ) rather than manually including/requiring it. The autoload functions themselves allow you to tell PHP how to actually load those classes. So, when you see something like: function __autoload($classname) { // stuff } $classname is automatically passed into the function by PHP itself when it encounters a class reference that hasn't been loaded yet. What this allows you to do is follow a certain naming and directory convention for your class files (like, say the PEAR/Zend convention), where each class resides in its own file, and its name actually represents the path to that class. So, Zend_Some_Class could map to zend/some/class. In order to fetch that with __autoload, you'd do something like (not tested): function __autoload($classname) { $classname = str_replace('_', DIRECTORY_SEPARATOR, strtolower($classname)); include($classname); } Hope this makes some sense.
-
Newbee Needs a little guidence urgently PLEASE!!
KevinM1 replied to HUMMER87's topic in PHP Coding Help
Where are these images coming from? Do you have a database table for them? The basics of what you want to do aren't difficult. The problem is that you haven't given anyone much to go on. A bare bones login system doesn't exactly infer what the rest of your system requirements are, especially since you haven't shared any code. Also, as a general forum etiquette tip, people generally don't respond to threads marked as urgent, nor do they respond to threads that don't have any code written in them. We're here to help, certainly, but we're not here to magically come up with a solution at the last minute so people can meet their work/school deadlines. -
1. Look into __autoload or it's more mature sibling spl_autoload_register 2. Whenever an object requires another object to work, the best thing to do is to give that first object a reference to that dependency. So, rather than create a new DBAL inside the object, you create the DBAL outside of it, and pass it in. That gives you flexibility, and since objects are passed by reference automatically in PHP 5+, it allows you to create one dependency that can be shared with multiple objects without doing something bad/dangerous like creating a singleton. This kind of activity is known as dependency injection, and is the way to go when one object needs to use another in order to do its job.
-
Take a look at your quotes....
-
Yeah, mountain time always gets the shaft. It's always funny trying to explain to people that there's indeed another timezone between central and pacific when I go to Yellowstone.
-
Matching one object value and pulling out array
KevinM1 replied to Ninjakreborn's topic in PHP Coding Help
You just need a simple linear search: <?php $highestPoints = 0.0; $highestObject; foreach ($array as $val) { if ($val->Q4Points >= $highestPoints) { $highestObject = $val; $highestPoints = $val->Q4Points; } } $id = $highestObject->ID; ?> -
Huh... figured out that my not being able to see it stems from the slideshow triggering my ad blocker. Not sure why, as I don't normally have problems with JavaScript or slideshows in general. Maybe it has to do where the images are hosted, or something about the slideshow script itself (a script from 2006 is ancient by modern standards. look into jQuery and an extension for it like jQuery Cycle, or one of the others). That said, the JavaScript and HTML errors remain.
-
Maybe it's for developers coming from environments where RAII is a concern? It would foster easier language adoption or app porting (think of the relatively common "Translate this Java/.NET script to PHP" questions we get) for those thrust into PHP.
-
You should post your slideshow code in our JavaScript section. It'll get more attention there. And, yeah, not fixing it is a problem, since right now there's a gaping hole where the slideshow should be. What browser(s) did you test with?
-
Look at the RAII link I posted above. Finally blocks are usually used as a place to close/dispose of resources (db connections, file handles, etc.). I'm not sure if PHP usually takes care of those kind of resources at the end of script execution or not (IIRC, db connections are automatically closed, but unsure about files), but in other languages resources aren't generally disposed by garbage collection, so finally blocks give the programmer a tidy place to do it.
-
Best practice: self::method() or $this->method()
KevinM1 replied to silkfire's topic in PHP Coding Help
That said, the convention is to use 'self' in a static context and 'this' in an instance context. Since just about everyone follows that convention, it's wise to stick to it. -
Finally.... But, yeah, good addition. Could help a little with RAII, although, I'm not sure how much of an issue it is in PHP.
-
Nope. Using Firebug, I see you have a couple JavaScript errors:
-
What's with the commented out image/huge gap at the top?
-
That's sad. Greenwich Mean Time (http://en.wikipedia.org/wiki/Greenwich_Mean_Time) is, aside from some details that most people don't have to care about, the same as Coordinated Universal Time (UTC - http://en.wikipedia.org/wiki/Coordinated_Universal_Time), which describes, among other things, how we divide up the planet's timezones. GMT/UTC is literally universal, and should be familiar to anyone that's ever had to adjust their timezone for an online app/site/forum. Of course, you could have saved yourself some trouble by simply doing this: http://lmgtfy.com/?q=gmt+time
-
Topic locked because soliciting partnership (e.g., "Someone help me write this script") is really more of a freelancing question/offer. EDIT: Obviously, if another mod feels it still fits, feel free to unlock. Kinda a gray area question, given how much code is in it.
-
#3 is your best bet. Pagination is not a Model, and Models are supposed to be 'dumb'. You should be able to query for the right data (in this case, the right set of db rows for a particular page), but the Model itself shouldn't be concerned with how its data is presented. It's primary concern is with data access/persistence. Assuming this is a MVC setup, the controller is the middle man. It should know what page has been requested, and query the Model for that data along with a count of all rows. It should then pass that data to the Pagination, along with ancillary info, like items per page and total number of rows, so it can properly display navigation. EDIT: Actually, your Pagination class should only have the ancillary info. Actual data should just be piped into the view. Again, separation of concerns - pagination only cares about page navigation, not actual data. Should have been clearer on that.
-
Let's say you have a URL like: www.example.com/index.php?cat=news In your PHP you'd need to check if: 1. 'cat' is present in the URL 2. that it's set to a value you'd accept If so, then load that data: $cat = strtolower($_GET['cat']); switch ($cat) { case "news": // SQL to retrieve news from the db break; // other cases based on whatever you need default: // normal home page } Keep in mind, that's just one way to do it, and it doesn't take security into account. Without knowing exactly what you want to do, I can't give a better answer.
-
This thread is about an inch from being locked. The only reason I haven't done it yet is because I feel there's some value in the discussion about hashing.
-
Locked for both being off-topic (asking about editors has nothing to do with PHP coding help), and because we have a stickied topic about just this thing in the Miscellaneous section: http://forums.phpfreaks.com/index.php?topic=277416.0 Protip: The other sections of this forum all exist for a reason.
-
If getting it out the door is a priority, I'd say yes, especially if there's money awaiting you upon completion. Frameworks = RAD (Rapid Application Development) = getting paid more often. Ultimately, that's why they exist. And, really, using a framework can be as valuable as digging through its code. There's something to be said for actually putting it through its paces and finding where the edge cases are. At the very least, you'll gain practical experience and insight into common pitfalls.
-
I'm not a big fan of CodeIgniter or Kohana. I used to be, but after I saw how they worked under the hood, I decided that they had some serious flaws. Symfony is nice, because it's as complex or simple as you want it to be. Each component of the framework is it's own standalone bundle, so you can decide to exclude whatever doesn't fit what you want to do. From what I've been able to see in its GitHub repository, it's pretty solidly built, too. But, back to design, the only time a super class really makes sense is if you're trying to create a Facade, where you have many different objects that interact with each other in one application layer (like, say, the domain) and want to hide the inner workings of that layer behind an interface. Even then, the Facade's job is simply to act as the gatekeeper and delegate to the actual objects that do stuff.