Do you guys typically put a function that returns a collection of objects inside the class for the object it returns? Something like: php:<? class User { static public function getUsers() { } } ?>
|
|
# ? Dec 19, 2008 01:58 |
|
|
# ? May 16, 2024 01:05 |
|
I put that in my data layer class(es) (generally my database class), as well as any other methods that would be fetching or manupilating data (e.g., SaveUser($user)).
|
# ? Dec 19, 2008 02:31 |
|
I'm having a pickle here. Is it better, when working on a large dataset inside a MySQL database, to do more complicated queries to select only the data you need, or risk select more than is needed then filter them out with PHP? I guess what I'm asking is how should I balance the load between MySQL and PHP processing? If I try to convert my code to use more SQL, I'm going to end up with a dozen JOINs and some other really abstract stuff. Not that I can't write it, no. I'm actually wondering if I'm not better off doing the complicated filtering with PHP.
|
# ? Dec 19, 2008 12:21 |
|
Sir Davey posted:I'm actually wondering if I'm not better off doing the complicated filtering with PHP. It's the database job to process the data, PHP to stick it in a template. Also consider stored procedures for extra processing in the database.
|
# ? Dec 19, 2008 12:31 |
|
surrealcatalyst posted:Don't you want to be comparing the input crypted by the original salt against the encrypted password, rather than decrypt the password? Yes, that's what I meant. Using the encrypted form of the original password as the salt works because it starts with the salt, i.e. its first 12 characters are the salt and PHP doesn't care if the salt is longer than it needs to be. At least that's my understanding of it.
|
# ? Dec 19, 2008 22:10 |
|
fletcher posted:Do you guys typically put a function that returns a collection of objects inside the class for the object it returns? I would generally have a class "User" and another for "UserDB" or something. i.e. one class for 'a user' and another that 'is' the store of all users. To get specific, I generally would be using CodeIgniter, so I'd have a UserModel, that handled interfacing with the DB, or whatever store it might be. That class would have the function that returned a collection of users. I would then have a class for a single user (which generally I would put in a helper, so I can use that abstraction outside CI if I want) and that generally has functions like render() I'm a big fan of a render() function at the moment, as it lets me pass the User objects to the view and then...render them. I do constantly question if thats 'good' MVC, but to me its neat; I can rely on consistant rendering of the markup for, say, an image, as long as I'm instanciating my image class (so I get alt tags etc) At some point I intend to make the common classes of this type I use also have an HTML rendering option, but I seem to be all xhtml these days. Anyway; I have wittered. Short version; no, no generating collections of an object from an object of that type. (but not saying its 'wrong' either)
|
# ? Dec 19, 2008 22:29 |
|
How do I convert a unix time stamp date to whatever the end user's time zone is? I notice the time() returns the UTC or whatever standard universal time zone. I'd like it to modify itself on the fly to whatever time zone the end user is in. And thus the "T" time zone parameter will correspond to whatever the end user's time zone is. My reference: http://us3.php.net/date
|
# ? Dec 20, 2008 11:10 |
|
You want date_default_timezone_set().
|
# ? Dec 20, 2008 11:20 |
|
supster posted:You want date_default_timezone_set(). Awesome, But how do I input the end user's time zone into that function? For now, I set it to always just display time as PST, but I'd like it to work for whatever the end user's time zone is. Much appreciated
|
# ? Dec 20, 2008 20:38 |
|
cannibustacap posted:Awesome, You'll either need to have the user input their timezone, or use Javascript to pick up the timezone offset from their computer settings, I think.
|
# ? Dec 20, 2008 20:52 |
|
Golbez posted:You'll either need to have the user input their timezone, or use Javascript to pick up the timezone offset from their computer settings, I think. Oh, so the user's time zone isn't in any of the server variables? or IP address?
|
# ? Dec 20, 2008 23:19 |
|
Nope. And IP addresses shouldn't really tell you what timezone someone is in unless you try and lookup where it's coming from. But even then, you'd probably get the wrong timezone because the internet is like that. Do I need to unset any class variables in __destruct() or does it do that by itself?
|
# ? Dec 20, 2008 23:39 |
|
I'd like to include a file but first make some regular expression substitutions to that file before including it. I have a website where I mixed HTML code and PHP code in my views. I am trying to clean up the code, and a friend suggested that I replace: <?getString("<key>");?> with ~gs=<key>~ While this replacement is simple, it does let me get rid of php code, and it saves me a few characters (which can be significant when I have 50+ getString calls in a single file). I have been able to store the file contents into a string, and do the replacements. However the problem then is that if I echo the string any php code doesn't get included. I've been able to replace ~gs=<key>~ with the result of calling getString(<key>), but there is other php code in my views that needs to get executed (thus doing echo is still not enough). I've tried eval but I'm hesitant to use it (security risks) and it is currently giving me an error. Some googling also suggested using a "clean" input file and then having a step to process it into the proper format for deployment, but I'd prefer to avoid the extra complexity of having two sets of files. Is there a better solution?
|
# ? Dec 20, 2008 23:45 |
|
cannibustacap posted:Oh, so the user's time zone isn't in any of the server variables? or IP address? So far as I know, the only way to know the user's time zone is either for them or their computer to tell you (though a form or javascript [which will still require a form to submit what Javascript picks up, I think]), or for you to guess through their IP, which is far from 100% and will cause more confusion than using a default zone.
|
# ? Dec 20, 2008 23:58 |
|
Just started with PHP, trying to write a form handler that will take some input from a POST form and write it to a text file. I can do the whole fopen, fwrite, fclose etc kind of thing when there's no form involved, but as soon as I use a form to execute the handler (even using the exact same code), I get permission denied. I know this isn't strictly a PHP question, but is there something about executing from a form instead of accessing the .php file directly that affects my file permissions? How can I get around this? my code: code:
quote:Warning: fopen(currentsong.txt): failed to open stream: Permission denied in /home/test.php on line 6
|
# ? Dec 21, 2008 01:19 |
|
drcru posted:Do I need to unset any class variables in __destruct() or does it do that by itself? chocojosh posted:Is there a better solution? That said, if you really want to do it you're looking for ob_start() and ob_get_clean(). You will start output buffering with ob_start(), include the file, and then save all the contents of the output buffer as a string into a variable with ob_get_clean(). Then you can do your string replacement with that variable and then simply print it.
|
# ? Dec 21, 2008 01:36 |
chocojosh posted:
Yea, use Smarty.
|
|
# ? Dec 21, 2008 02:22 |
|
I've decided for the moment to not bother doing anything fancy to the update of the views. I don't really want to touch output buffering because I'm already using it (I believe because there was issues getting session to work properly with the way the site is structured), and I don't want any conflicts/bugs to happen. I've decided for now to use what I have (it works and it's not painful for me to make changes because I'm familiar with the site design; it's a one person project that needs a few days of work once a year). I've been taught it's bad structure to be mixing in business logic with views. For example here's the code to make sure the proper radio button is selected on a load ($var will be retrieved from the database); my code has many other examples like this: code:
|
# ? Dec 21, 2008 04:09 |
|
chocojosh posted:I think though that using a proper templating system would be the best way to go. php:<? /* controller */ $data = array( array( value => "1", label => getString("none") ), array( value => "2", label => getString("small") ), array( value => "3", label => getString("small") ) ); foreach ($data as &$datum) { $datum["selected"] = $datum["value"] == $var; } ... ?> php:<? /* view */ ?> <div> <? foreach ($data as &$datum) { ?> <option value="<?=$datum["value"]?>"<?=$datum["selected"]?" selected":""?>> <?=$datum["label"]?> </option> <? } ?> </div>
|
# ? Dec 21, 2008 06:39 |
MrMoo posted:PHP is a proper template system This is true, and I totally understand the arguments against Smarty saying its not necessary. It's just that it makes it more work to take little shortcuts and really forces you to abstract your views.
|
|
# ? Dec 21, 2008 11:57 |
|
Emo.fm posted:Just started with PHP, trying to write a form handler that will take some input from a POST form and write it to a text file. I can do the whole fopen, fwrite, fclose etc kind of thing when there's no form involved, but as soon as I use a form to execute the handler (even using the exact same code), I get permission denied. I know this isn't strictly a PHP question, but is there something about executing from a form instead of accessing the .php file directly that affects my file permissions? How can I get around this? It's crapping out before it even gets to the POST bit, so it doesn't look like that's the problem. You are *sure* it works w/o the POST? It won't change if the page was just loaded, or if it was sent POST data. Replace $_POST['song'] with "lolz" and see if you get the same error when you load the page.
|
# ? Dec 21, 2008 23:37 |
|
Golbez posted:You'll either need to have the user input their timezone, or use Javascript to pick up the timezone offset from their computer settings, I think. Okay well what is the most efficent way to have javascript pick up the user's timezone and feed it into the PHP date functions?
|
# ? Dec 21, 2008 23:53 |
|
cannibustacap posted:Okay well what is the most efficent way to have javascript pick up the user's timezone and feed it into the PHP date functions? Thing is, I don't know if this can be automatic. The way Wikipedia does it is, there's a button the user clicks which tells (I'm guessing here) Javascript to find out the time offset, and then the user has to click 'submit'. Wikipedia needs this due to its very international audience; for a normal American website, you may be better off with a simple "Atlantic/Eastern/Central/Mountain/Pacific/Alaskan/Hawaiian" dropdown list.
|
# ? Dec 22, 2008 00:34 |
|
cannibustacap posted:Okay well what is the most efficent way to have javascript pick up the user's timezone and feed it into the PHP date functions? Eg: +10 GMT is going to be -600 (Provided they have the correct timezone setting on their OS) Scuzzy fucked around with this message at 00:58 on Dec 22, 2008 |
# ? Dec 22, 2008 00:45 |
|
Thiscode:
But I'd be hosed if I know what it is.
|
# ? Dec 22, 2008 02:46 |
|
duck monster posted:This Possibly solved my own question code:
|
# ? Dec 22, 2008 03:28 |
|
cannibustacap posted:Okay well what is the most efficent way to have javascript pick up the user's timezone and feed it into the PHP date functions? If you are storing information about the user, perhaps you can require them to pick a timezone at some point? If not, you could just use javascript to get their timezone, throw it into a hidden field and read it on the back end into session data. If neither of those work for your situation, I bet you could send the time in the server's local time to the client, and convert it to the user's local time by modifying this to fit.
|
# ? Dec 22, 2008 04:48 |
|
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):code:
I'm tempted to kill the left margin on the text and pretend like the bleed is on purpose, but I figure I may as well try to do it right first before I chump out. Edit: I managed to shrink the line height enough to make the stars work they way they're formatted now, although ideally I'd rather have them on the same line as the date. I added "line-height:0%" to the text style to do that. But I still have some covering up the line immediately after the image. IndieRockLance fucked around with this message at 06:39 on Dec 22, 2008 |
# ? Dec 22, 2008 06:14 |
|
IndieRockLance posted:stuff. That's some messy, messy code there. For one thing, your anchor tag doesn't follow XML specification. It should be like this: code:
|
# ? Dec 22, 2008 09:38 |
|
Mackerel, the Thief posted:In addition, I've never heard of someone applying a background url to an img tag. Apply it to a div. Its perfectly valid CSS though, so it should be OK. (can't say for sure if browsers will do it properly...) Agree with the messy code though; use CSS from an external file rather than string-concatenating a style attribute together; much more stylish! KuruMonkey fucked around with this message at 21:49 on Dec 22, 2008 |
# ? Dec 22, 2008 21:42 |
|
KuruMonkey posted:Its perfectly valid CSS though, so it should be OK. (can't say for sure if browsers will do it properly...) Yeah, it works. It's not pretty, but it works. I changed it to apply to the div though, just to be on the safe side (I also stuffed all that style data into the CSS file like I should have). I think I solved my problem by changing the last p to a div. I'm sure there are more elegant solutions but it works and I can busy myself with cleaning up my mess after everything's functioning.
|
# ? Dec 22, 2008 22:29 |
|
I have a php project that is using cheap shared web hosting and developed directly on the source code because for the life of me I cannot get XAMPP's mail to work properly with the web hosting's SMTP server. The project is becoming much bigger than originally anticipated and I need to get my source control on. It's no problem to install SVN on my local machine and check into it from my local workspace but I don't know how to correctly have it match up with my web hosting. Is there any way that I can synchronize directories over FTP? Is there any better way that I should be planning on doing this? Thanks.
|
# ? Dec 22, 2008 22:42 |
sonic bed head posted:The project is becoming much bigger than originally anticipated and I need to get my source control on. It's no problem to install SVN on my local machine and check into it from my local workspace but I don't know how to correctly have it match up with my web hosting. Is there any way that I can synchronize directories over FTP? Is there any better way that I should be planning on doing this? Thanks. Sounds like you want a build script that will take things out of SVN and put them on the server. I have a development build and then I copy files I have updated from that to my local machine, check them into SVN, and then from the server do something like: ./build-production-website.sh I never manually modify the files in the production build, only my build script modifies things in production. The main purpose of the script is to do an svn export but you can have it do all kinds of useful things like setting permissions, running database update scripts, etc that are needed to do a build.
|
|
# ? Dec 22, 2008 22:52 |
|
fletcher posted:Do you guys typically put a function that returns a collection of objects inside the class for the object it returns? I do this and it works just fine for me. Makes the most sense that a function related to a certain functionality should be in the namespace of the corresponding data structure. I have no problem calling user::get_users() unless I'd be doing it some non-static way like $search_engine->get_users();
|
# ? Dec 22, 2008 23:24 |
|
KuruMonkey posted:Its perfectly valid CSS though, so it should be OK. (can't say for sure if browsers will do it properly...) Firefox will. I use a swirling thingy as the background image of a thumbnail generator since the thumbnails can take several seconds before they're ready.
|
# ? Dec 23, 2008 01:10 |
|
Is there a better way to parse a string for certain words? Something like search string for any of these array keys and if you find one do something with the value of that key. Description = Cisco IOS Software, C2960 Software (C2960-LANBASE-M), Version 12.2(35)S code:
|
# ? Dec 24, 2008 03:50 |
|
Hey I want to make a list of links where only the selected link is bold, the rest are normal. Just like here http://www.amazon.com/gp/bestsellers/electronics/1036922/ref=pd_ts_e_nav Notice how DVD Players is bold and the rest are normal? How would I, either in PHP or CSS, make that happen?
|
# ? Dec 24, 2008 20:53 |
|
CSS AND PHP would work if you want. Just change the style for that one link and add some sort of check to see where you are on the site.
|
# ? Dec 24, 2008 21:29 |
|
php:<? ?> <ul id="item-list"> <?php foreach($item_list as $item) { ?><li<?php if ($item == $selected_item) { ?> class="selected"<?php } ?>><a href="URL">ITEM TITLE</a></li><?php } ?></ul><?php ?> code:
Internet Headache fucked around with this message at 21:49 on Dec 24, 2008 |
# ? Dec 24, 2008 21:47 |
|
|
# ? May 16, 2024 01:05 |
|
fletcher posted:Sounds like you want a build script that will take things out of SVN and put them on the server. I have a development build and then I copy files I have updated from that to my local machine, check them into SVN, and then from the server do something like: ./build-production-website.sh I would really like to do something like this but I don't really know how to achieve it on a windows machine with no ssh access to my web hosting. I can only use FTP. Can I write a .bat that can do this using windows native ftp CLI?
|
# ? Dec 24, 2008 22:58 |