|
Does everyone else find themselves constantly typing ampersands in every function definition and assignment when dealing with (potentially) large data structures (usually database result sets)? It's so annoying . I wish we could either get actual pointers or real references.
|
# ? Dec 25, 2008 12:30 |
|
|
# ? May 16, 2024 17:44 |
|
Thanks a lot and Merry Christmas
|
# ? Dec 25, 2008 13:37 |
|
IndieRockLance posted:I've been trial-and-erroring my way though modifying a Wordpress template and I've run into a problem that I can't figure out. On the archives page, I'm having it generate thumbnails from the posts, overlay a transparent PNG and overlay the post titles over those matte images. Here's my code from the archives.php page (breaks added for clarity): Must....clean up...code.... archive.php php:<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php $thumbnail = get_post_meta($post->ID, 'thumbnail', true); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2> <div class="entry"> <div class="thumbnail_container"> <img src="<?php echo $thumbnail; ?>" alt="<?php the_title(); ?>" /> <span class="gloss"></span> </div> <?php the_post('Read the rest of this entry...'); ?> </div> <p class="postmetadata"><?php the_time('M d, Y'); ?><?php if (function_exists('the_ratings')) { ?> | <?php the_ratings(); } ?></p> </div> <?php endwhile; endif;?> style.css code:
The idea is that you should display an image like normal (no tricky, dynamically-generated CSS background tricks), then use a <span> tag to absolutely position the partially-transparent PNG overlay right on top of it. Zorilla fucked around with this message at 19:55 on Dec 25, 2008 |
# ? Dec 25, 2008 19:36 |
|
Do you guys know the text field on the upper right of the main page on Facebook, the friend search? It auto suggests names from your own friends as you type. Is there some way to do this with PHP/MySQL for my own site? I'm making a site for inputting songs as they're played (college radio station, yay) and would like some way to suggest the correct spelling/formatting of songs and artists (pulled from a database) so that we don't end up with 15 different entries for "Beatles" "The Beatles" "Beetles" "Beatls" etc.
|
# ? Dec 27, 2008 18:15 |
|
Emo.fm posted:Do you guys know the text field on the upper right of the main page on Facebook, the friend search? It auto suggests names from your own friends as you type. Is there some way to do this with PHP/MySQL for my own site? I'm making a site for inputting songs as they're played (college radio station, yay) and would like some way to suggest the correct spelling/formatting of songs and artists (pulled from a database) so that we don't end up with 15 different entries for "Beatles" "The Beatles" "Beetles" "Beatls" etc. Not with PHP alone, but with AJAX. I would probably do something with jQuery that ties an AJAX request to an onkeyup event for that input field. That AJAX request would run a PHP script that returns suggestions in JSON format. You would definitely have to optimize it so that it's not running a MySQL query every single time somebody presses a key. (Maybe once every 3-5 seconds while typing is better) Zorilla fucked around with this message at 18:44 on Dec 27, 2008 |
# ? Dec 27, 2008 18:40 |
|
Zorilla posted:Not with PHP alone, but with AJAX. I would probably do something with jQuery that ties an AJAX request to an onkeyup event for that input field. That AJAX request would run a PHP script that returns suggestions in JSON format. Thanks, I will look into this. Another dumb PHP question -- is there a function for finding out the current page being displayed? As in, let's say I want to do a standard "footer.php" and include it with each page, but not include a link to the current page. Is there a simple way to find that out?
|
# ? Dec 28, 2008 04:35 |
|
edit: durr, I thought you were talking about WordPress for some dumb reason. Just listen to the guy below me.
Zorilla fucked around with this message at 06:14 on Dec 28, 2008 |
# ? Dec 28, 2008 05:51 |
|
Emo.fm posted:Thanks, I will look into this. $_SERVER['REQUEST_URI'] is usually what was typed in the address bar to get to the page, and $_SERVER['PHP_SELF'] is usually the main or "parent" page (meaning, if index.php includes footer.php, PHP_SELF on either page will be index.php). Server configuration changes the values and formats of those variables, so you might just want to make a page that spits out phpinfo() and look at the variables yourself. Some servers give multiple formats for the same information, so it might be easier to match one or the other to the link hrefs as you echo them.
|
# ? Dec 28, 2008 05:55 |
|
cannibustacap posted:Hey I want to make a list of links where only the selected link is bold, the rest are normal. Make the bold style the default for the list (e.g. non-linked text). Make your links non-bold. Remove the link on the selected item. Done.
|
# ? Dec 28, 2008 06:35 |
Let's say you have a User class and an Article class and you want a function that returns all the articles a user has written. Does it go in the Article class as something like Article::getArticlesByUser($user) or in the User class like $user->getArticles()? What makes more sense?
|
|
# ? Dec 28, 2008 09:21 |
|
fletcher posted:Let's say you have a User class and an Article class and you want a function that returns all the articles a user has written. Does it go in the Article class as something like Article::getArticlesByUser($user) or in the User class like $user->getArticles()? What makes more sense? Gonna go out on a limb and say this is up to taste. Maybe there's an official way and I'm full of poo poo, though. I could easily imagine doing it either way depending on how I've chosen to design an application.
|
# ? Dec 28, 2008 10:51 |
|
fletcher posted:Let's say you have a User class and an Article class and you want a function that returns all the articles a user has written. Does it go in the Article class as something like Article::getArticlesByUser($user) or in the User class like $user->getArticles()? What makes more sense? I would do it the latter way. No reason to do a static function when you can have one less parameter.
|
# ? Dec 28, 2008 11:00 |
|
fletcher posted:Let's say you have a User class and an Article class and you want a function that returns all the articles a user has written. Does it go in the Article class as something like Article::getArticlesByUser($user) or in the User class like $user->getArticles()? What makes more sense? I was about to say "depends", but in this case it really doesn't. $user->articles(); is fine. Article::articles_by_a_user(); makes little sense. Think of it like this; once you "have" a user, it makes sense (in the vague context of a system that stores articles by users) to find all the articles by a user. I can think of a strong user case where I'd want to do that, and I can imagine I might have an instance of a user then too. (I can think of 2 clear cases; show more articles by current article's author, or when author logged in, show my articles) On the other hand (and I'll be honest we've only got the name of the class Article, singular, to go on) it seems you've conceived of an abstraction for A USER and one for AN ARTICLE,singular in both cases. A function belonging to a singular abstraction that returns a set of (somethings) which is related to that instance; this makes sense. A static function of a singular abrstraction that produces a set of that type of object, related to an instance of a different type? Nonsensical. In fact I feel I've kind of aswered this before? I think you would be well served by a book on OO, preferably one well separated from any specifics of a language you are interested in programming in. It also occurs that you might want to look into the concepts of factories, or at least become open to the idea of using multiple abstractions for the same "thing". i.e. how about 2 classes; Article and Articles; the former to abstract an individual and specific article, the second to abstract the colection of all articles, and provide functions that produce sub-collections (as, say, arrays of Article) So you could have Articles::by_author($user_id) which returns an array[Article]... This would then also be the logical place to put Articles::most_recent(10); and Articles::awaiting_publishing(); etc etc (note these may well NOT actually want to be static functions, and in terms of MVC Article and Articles are both models, which give different interfaces to the same resource...)
|
# ? Dec 28, 2008 14:38 |
|
KuruMonkey posted:i.e. how about 2 classes; Article and Articles; the former to abstract an individual and specific article, the second to abstract the colection of all articles, and provide functions that produce sub-collections (as, say, arrays of Article) What's the point of having a seperate class for "Articles?" I can't see what data this object would contain except that of an array of objects of type "Article"... I fail to see the necessity of creating something like Articles::most_recent(int) when Article::most_recent(int) would make just as much sense. It seems like OOP dogma more than anything practical imho.
|
# ? Dec 29, 2008 21:32 |
|
How am I supposed to handle timezones in php? The DateTime object seems bloated and unportable. Edit: What I meant to ask is, what method do you personally prefer for handling timezones in php and other web languages? Khorne fucked around with this message at 23:35 on Dec 29, 2008 |
# ? Dec 29, 2008 23:18 |
|
Atom posted:I fail to see the necessity of creating something like Articles::most_recent(int) when Article::most_recent(int) would make just as much sense. It seems like OOP dogma more than anything practical imho. There's no 'necessity' its a nicety of abstraction. In the cold light of pure practicality there's no need to seperate the abstraction of the collection of items from the abstraction of the items themselves. (just as there's no 'necessity' to write in an OO style in PHP at all, you could even still implement MVC in a purely procedural programming method, probably clumsy, but you could do it if it suited your purpose) On the other hand, it can serve a purpose to seperate into 2 abstractions the functionality that applies to the group from that which applies to the individual. Example; changing the headline of an article probably 'belongs' in an abstraction for the article as an individual item, but finding all articles with a given feature is (potentially) a feature of the group of articles as a whole. Further example, you could possibly write this pair of classes so that modifying the implementation of one did not imply a need to change the implementation of the other - and in some cases that alone might be reason to split into 2 classes. Conversely, considerations of further (as in to come at a later date) extensions to Article might mean that having it all wrapped up in one class to inherit from was helpful. It really come down to; there needs to be an underlying understanding of the flow of your data, the structure of your data and the intended (and expected) use cases for the classes and objects your making. This all gels together to give you a 'feel' of what is the correct abstraction for your application. The question (certainly when taken in combination with the poster's previous one) was taken in a sense of 'what would you do?' Hence my comment about the OO book; not meaning to imply 'and then you too would understand the ONE TRUE ABSTRACTION for users and articles in all systems' but that this would be the place to look for a wider view of how to go about crafting the abstractions that will work for the specific app at hand; because there are many perfectly valid ways to abstract authors and articles (I mean; is this a 1-1, 1-M, M-1 or M-M relationship in this application? Is this even decided yet? Because that would change EVERYTHING!) I've certainly never considered myself dogmatic about OO (slack about it, yes, dogmatic - no) I gave an answer of how I would do it, why I would do it that way, and why I wouldn't do it the other way - and a suggestion to go look at other ways - where the dogma at? Edit; and my god I can witter on about this stuff
|
# ? Dec 30, 2008 01:39 |
|
Khorne posted:Edit: What I meant to ask is, what method do you personally prefer for handling timezones in php and other web languages? I don't do a lot with timezones, honestly (its a perk of living in GMT - just make everything Zulu and forget about it) But; when I do, I simply... 1-store all times as Zulu 2-manually offset by any required timezone offset using the magic of addition and subtraction, at the point the offset is required (i.e. I brute force it) I'm probably anomalous though, because I tend not to use stuff thats only in PHP 5, because of ending up wanting to get my code running on clients' lovely shared hosting that they will not change. So I tend to use time() and microtime() and strftime() more than maybe is normal/sane. p.s. I use the same methods for currencies (store all as GBP and convert as required) and measures (SI units and convert).
|
# ? Dec 30, 2008 01:52 |
|
KuruMonkey posted:I've certainly never considered myself dogmatic about OO (slack about it, yes, dogmatic - no) I gave an answer of how I would do it, why I would do it that way, and why I wouldn't do it the other way - and a suggestion to go look at other ways - where the dogma at? Forgive me perhaps dogma was not the correct term. I just can't see a reason for doing it that way other than for adherence to a self-imposed standard.
|
# ? Dec 30, 2008 01:58 |
|
Atom posted:adherence to a self-imposed standard. Yeah; thats pretty much accurate. To the extent that I'd not use a singular name (article) for anything that included functionality for a collection (articles). I mean, I frequently write code like this; php:<? foreach($cats as $cat) { $cat->stuff(); } ?> But thats off in the lands of 'how do you name YOUR classes?!?' Which is just faffery Edit; I will however put on my software QA hat, and defend to the hilt that having a standard (self selected or official) and sticking to it is Good Practice. Oh yes.
|
# ? Dec 30, 2008 02:14 |
Lots of interesting comments! Thanks guys. I figured it had more of a clear cut answer but it seems that is not the case! I think it's definitely time to pick up a book about OOP.
|
|
# ? Dec 30, 2008 08:39 |
|
I'm looking for something to help with my daily work tasks, as well as recording the information I find while doing these tasks. I need to check server hard drive usages, modify certain profile information, clean out workstations at specific time intervals, etc. I'm looking for some kind of task or to do site I can set up with PHP and MySQL where I can automate things a bit. I need tasks that repeat daily (but not on weekends, more configuration options would be nice), the ability to add one time tasks, and be able to go back to show that I did what was supposed to be done. This will be for my use only, others won't be able to log in and create their own tasks. Anyone know if such a thing exists?
|
# ? Dec 31, 2008 18:15 |
|
Yaksha posted:I'm looking for something to help with my daily work tasks, as well as recording the information I find while doing these tasks. I need to check server hard drive usages, modify certain profile information, clean out workstations at specific time intervals, etc. If it's for your own use only, is there a reason you want to host it yourself? Cause Remember The Milk does all that stuff you said and more, and is free. You can specify tasks to repeat "every day", "every weekday", or even "every month on the 2nd last Friday". Tasks can have subtasks (or not), and you can keep finished tasks to take a look at past progress.
|
# ? Jan 1, 2009 03:02 |
|
I'm in no way a coder, I just play with Joomla and edit other people's hard work. I'm having an issue with a template I've been working with and I was hoping someone could give me a hand. The site is here: (alttabbed.net is not my site) http://www.alttabbed.net/revdemo This is a Joomla site with the "Simplix" template installed from Rockettheme. I've been tweeking it for the last couple days and it's almost looking exactly how I want. The image is the article and the text and the menu are in modules. My hope was to be able to get them all to line up, top and bottom, however if I extend the image to it's full height of 450 (the height of the two modules), the middle module extends down further for no reason whatsoever. I think this may be a padding/margin thing but I'm an idiot and can't find anything related to that in the CSS file. The image also seems to start a couple pixels below the modules. Also, in Firefox and a few other browsers the site looks fine, but in IE7/8 it only takes up 3/4 of the screen and the rest is white. I know I can't explain poo poo very well, but if someone is familiar with Joomla and could help me out it would be greatly appreciated. edit: Well, I fixed the to alignment, but the middle module still extends when the image is set to 500px. IE/Chrome issue, I still have no idea. edit2: I think I fixed everything. Envy Insanity fucked around with this message at 17:28 on Jan 1, 2009 |
# ? Jan 1, 2009 09:21 |
|
KuruMonkey posted:I don't do a lot with timezones, honestly (its a perk of living in GMT - just make everything Zulu and forget about it) quote:But; when I do, I simply... The right way to do it is to store the symbolic zoneinfo timezone name e.g. "Europe/Berlin" and call php:<? $timezone = $user->getPreferredTimezone(); // or whatever date_default_timezone_set($timezone); ?>
|
# ? Jan 1, 2009 19:06 |
|
I've been trying to create a multipart text/html email and for some reason I can't get it to read properly. Here's what I've been doing, following examples of mime types on Google:code:
Can anyone point out what the issue with my code is? Thanks
|
# ? Jan 2, 2009 16:09 |
|
Stephen posted:I've been trying to create a multipart text/html email and for some reason I can't get it to read properly. Here's what I've been doing, following examples of mime types on Google:
|
# ? Jan 2, 2009 16:50 |
|
Awesome, thanks. I fixed those and noticed I had the semicolon inside the boundary definition which was obviously breaking it as well. Now I've got it working. Both the HTML and text parts of the mail message are showing up, however I was under the impression that only one part should appear, depending on if the user has HTML message enabled or not. As it is, in my HTML enabled gmail window, both parts of the message are showing, and in a client with HTML disabled, both parts are also showing and all the HTML code is appearing as text. Edit: Nevermind, changed the MIME type to multipart/alternative and it worked great! Thanks again for the help Stephen fucked around with this message at 17:33 on Jan 2, 2009 |
# ? Jan 2, 2009 17:28 |
|
Stephen posted:Multipart email stuff PHP also supports heredoc statements, which is good for large blocks of text you don't want to use PHP's templating system for: code:
php:<?php $email["friendly_name"] = "E-mail"; $email["address"] = "email@myaddress.com"; ob_start(); ?> From: <?php echo $email["friendly_name"]; ?> <<?php echo $email["address"]; ?>> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="boundary123" <?php $headers = ob_get_contents(); ob_end_clean(); ob_start(); ?> --boundary123 Content-Type: text/plain Here's some content --boundary123 Content-Type: text/html <html> Here's some HTML content </html> --boundary123-- <?php $body = ob_get_contents(); ob_end_clean(); mail($to, $subject, $body, $headers); ?> Zorilla fucked around with this message at 18:09 on Jan 2, 2009 |
# ? Jan 2, 2009 17:49 |
I've been a big fan of EditPlus for awhile now for all my PHP needs. I really find myself wanting an object outline and some basic auto-completion sometimes. Are there any lightweight editors that do that for PHP on windows? I like Eclipse for Java but didn't really like it for PHP.
|
|
# ? Jan 4, 2009 10:59 |
|
You could try Aptana with the PHP plugin. It's based on Eclipse and has a lot of neat built-in stuff specifically for web development. https://www.aptana.com
|
# ? Jan 4, 2009 15:10 |
SuckerPunched posted:You could try Aptana with the PHP plugin. It's based on Eclipse and has a lot of neat built-in stuff specifically for web development. Looks neat but this is the exact opposite of "lightweight"
|
|
# ? Jan 4, 2009 21:55 |
|
Well yeah but I was going off your "I like Eclipse" statement.
|
# ? Jan 4, 2009 22:59 |
|
fletcher posted:I've been a big fan of EditPlus for awhile now for all my PHP needs. I really find myself wanting an object outline and some basic auto-completion sometimes. Are there any lightweight editors that do that for PHP on windows? I like Eclipse for Java but didn't really like it for PHP. I'm in the middle of evaluating NuSphere PhpEd. It's not as lightweight as EditPlus, but I imagine that would be true of any IDE that can outline objects and complete code. It's nowhere near as heavyweight as Eclipse or Visual Studio, either. So far I'm really impressed. I downloaded a massive project (around 10MB of source code) for local development. Frankly, I expected PhpEd to get a little confused about the class hierarchy. I opened a script and instantiated a derived class that depends on an autoload function for inclusion. The editor gave me all of its public members without a hiccup. It includes doc comments in the code completion if they exist (method and argument descriptions, etc.). And this is on an antiquated Thinkpad running XP Pro with 512MB of RAM. Unfortunately, it's also not as cheap as EditPlus, but a free trial is available. DaTroof fucked around with this message at 00:56 on Jan 5, 2009 |
# ? Jan 5, 2009 00:36 |
Thanks guys I'll give both a shot. Here's a general question, let's say I have a function like before like $user->getArticles() but I want to limit my results to certain articles, like ones filed under $category about $topic written on $date with $coAuthor, etc etc with all these different things and before you know it I'm passing in 15 arguments to getArticles(...), what's a better way of doing that? Are you supposed to make some kind other ArticlesFilter class where I can specify $articleFilter->setCategory('Technology') and then I just pass in my filter object: $user->getArticles($articlesFilter) ? fletcher fucked around with this message at 09:05 on Jan 5, 2009 |
|
# ? Jan 5, 2009 08:53 |
|
You could always just accept arrays as input. ie. php:<? $where = array( 'category' => $category, 'topic' => $topic ); $user->getArticles($where); ?>
|
# ? Jan 5, 2009 12:34 |
|
Let's say I have a list of variables I would like to pass to my php script, such as http://someurl?a=2&b=3. What if I want to pass a string "a=2&b=3" as a single variable? like http://someurl?args="a=2&b=3". How can I do this? I tried quotes already and they don't work. Is there some particular escape character I can use or something?
|
# ? Jan 5, 2009 17:57 |
|
hexadecimal posted:Let's say I have a list of variables I would like to pass to my php script, such as http://someurl?a=2&b=3. What if I want to pass a string "a=2&b=3" as a single variable? like http://someurl?args="a=2&b=3". How can I do this? I tried quotes already and they don't work. Is there some particular escape character I can use or something? see http://ca3.php.net/manual/en/function.urlencode.php
|
# ? Jan 5, 2009 17:59 |
|
Murodese posted:You could always just accept arrays as input. Yeah but if you're going to use an associative array you might as well use an object imho. I hate looking at code that takes associative arrays as input because an associative array doesn't have an explicit structure where an object does.
|
# ? Jan 5, 2009 20:33 |
|
Atom posted:Yeah but if you're going to use an associative array you might as well use an object imho. I hate looking at code that takes associative arrays as input because an associative array doesn't have an explicit structure where an object does. As I'm nowhere near a classically trained programmer, can you explain what the difference is to me? What do you mean by an explicit structure? To me they are pretty much the same thing because a class with public variables still has to have it's variables set in much the same way as an associative array. Is the benefit just better design or somehow optimized code?
|
# ? Jan 6, 2009 14:34 |
|
|
# ? May 16, 2024 17:44 |
|
sonic bed head posted:As I'm nowhere near a classically trained programmer, can you explain what the difference is to me? What do you mean by an explicit structure? To me they are pretty much the same thing because a class with public variables still has to have it's variables set in much the same way as an associative array. Is the benefit just better design or somehow optimized code? In any case I don't like passing either arrays or objects as input unless necessary, so this is what I would do. It's the $where array approach with methods. php:<? $articledb = new ArticleDatabase($db); $articledb->filterCategory('balls'); $articledb->filterTopic(1); $articledb->filterDate(false, '2009-01-01'); $user->articles = $articledb->fetch(); class ArticleDatabase { // Store filters to be returned to buildQuery later protected $filters = array(); public function filterCategory($cat) {} public function filterTopic($topicId) {} public function filterDate($dateBegin, $dateEnd=false) {} public function fetch() { $this->buildQuery(); // run query and initialize ArticleResult with the database result return new ArticleResult($result); } protected function buildQuery() {} } class ArticleResult implements Iterator { public $title; public $category; public $date; protected $result; // Check php manual for the native Iterator class // to give array-like access to the articles result public function current() { return $this->result->fetch_object(); } // etc } ?>
|
# ? Jan 6, 2009 17:13 |