|
alucinor posted:.htaccess question: code:
|
# ? Jun 4, 2012 17:15 |
|
|
# ? May 19, 2024 17:10 |
|
It's rather odd that a parameter like that in the request causes your site to throw a 404. I'd check that out first. Second, I don't know for sure, but isn't this more valid for rewriting:code:
|
# ? Jun 4, 2012 17:19 |
|
Doh004 posted:I think something like this would work? It's just off the top of my head and I don't have time to test it out here. Thanks so much, I really appreciate it. Sadly this gives me an Internal Server Error. This (note the leading slash after the carat): code:
What about matching ANY incoming URL containing "tokenid" anywhere in the URL? Looking at my analytics data, I see tokenid urls followed by a few different alphanumeric strings, but my site doesn't use "tokenid" so they all must from the same referrer. I tried: code:
geonetix posted:It's rather odd that a parameter like that in the request causes your site to throw a 404. I'd check that out first. Second, I don't know for sure, but isn't this more valid for rewriting: No kidding. We're using a 10 year old proprietary custom CMS which is no longer supported by the developers. Only about 8 more months till we upgrade! Tried this variant, still nothing.
|
# ? Jun 4, 2012 17:40 |
|
Try this for the condition:code:
|
# ? Jun 4, 2012 17:52 |
|
Also are rewrites working at all? You should have AllowOverride set to all in httpd.conf for that site for .htaccess files to even work.
|
# ? Jun 4, 2012 17:56 |
|
revmoo posted:Also are rewrites working at all? You should have AllowOverride set to all in httpd.conf for that site for .htaccess files to even work. Definitely working. I have a dozen other rewrites and scores of redirects, and I even checked to make sure there aren't any in conflict with this one. Doh004 posted:Try this for the condition: Nope. Thanks to all, at least I feel better that I didn't miss some really stupid obvious solution. I'm gonna poke around in the site code, maybe this CMS does use tokenid somewhere, that would explain why I can't rewrite it without it throwing the internal server error. Edit: Ok wait, just realized that google analytics is showing hits on example.com/?tokenid=fbb7e521-21da-4db2-97eb note the missing & before tokenid. Does that change anything? alucinor fucked around with this message at 18:13 on Jun 4, 2012 |
# ? Jun 4, 2012 18:11 |
|
alucinor posted:Edit: Ok wait, just realized that google analytics is showing hits on Edit: Why not just do this in the root of the site that is being referred to: php:<?php //index.php if ($_GET['tokenid'] == 'fbb7e521-21da-4db2-97eb') { header('Location: http://www.example.com'); exit; } ?> DarkLotus fucked around with this message at 19:01 on Jun 4, 2012 |
# ? Jun 4, 2012 18:53 |
|
Edit* ^^^^ Do that alucinor posted:Edit: Ok wait, just realized that google analytics is showing hits on Also, here's how I handle query strings for my app: code:
|
# ? Jun 4, 2012 19:00 |
|
DarkLotus posted:The first item in the query string is always preceded by a ?. I'm guessing the referring site wrote the query string wrong but Google is picking it up properly. That works! Sorta. Now I see the homepage content instead of the 404 page, but the site is not delivering the homepage template (home page has a sidebar menu, internal pages do not). Close enough. Hate this CMS so much. Thank you again!
|
# ? Jun 4, 2012 19:10 |
|
Anyone know anything about this book? I just saw it advertised here and wasn't sure if it was goon-written. My group decided to do our senior project in PHP, even though none of us are good in PHP so I figured some summer literature couldn't hurt for classes next quarter.
|
# ? Jun 4, 2012 19:18 |
|
I have a bit of a best practice question. I'm writing a model that will obviously have multiple ways of fetching the same data (Users for example can be fetched byId, byUsername, byEmail etc). Obviously this means each of those methods will need to fetch the same database fields, package them into the User class and then return that class instance. This opens up potential for lots of code repetition. I'm not explaining myself very well, I can tell already, so I'll give an example: php:<? class User { ... public static function byId($id) { $CI = get_instance(); $CI->db->select('us.user_id, us.user_name, us.user_email'); $CI->db->where('us.user_id', $id); $r = $CI->db->get('user us'); return new User($r->result()); } public static function byEmail($email) { $CI = get_instance(); $CI->db->select('us.user_id, us.user_name, us.user_email'); $CI->db->where('us.user_email', $email); $r = $CI->db->get('user us'); return new User($r->result()); } ... } ?> (By the way, I'm using CodeIgniter if you hadn't guessed). Edit: Also, bonus question! I have a User class wherein one of the properties represents the user's favourite AFL team. This property is called team and holds a Team object. Now, every time I want to get a User out of the database, I'd like to get their favourite team as well, so I can create the Team object and set it against the 'team' property for that User. Obviously I will also have a Team model and there will be other models as well that will need to have a "Team" as one or more of the class properties. Obviously I can just include the team details in the query, get it all out and once and set it all up how I want it. But say a few months down the track I want to add an extra field to the Team table. Now I have a hundred different places where I'm fetching Team details that I need to update to also fetch the new field. How do I prevent this being an issue? Help! putin is a cunt fucked around with this message at 11:33 on Jun 5, 2012 |
# ? Jun 5, 2012 11:25 |
|
You could use the __call() magic method, something along the lines of:php:<?php class User { public function __call($method, $argv) { $field = strtolower(str_replace('by', '', $method)); // Maybe do some other logic to convert camelCase to unix_case. // So, byUserId would become user_id $db->where(sprintf('us.%s', $filed), $argv[0]); // Fill in the rest here return(new User($r->result())); } } I don't know enough about CI to help you with your second question, but you should look into using a real ORM that can handle cross references like that.
|
# ? Jun 5, 2012 12:21 |
|
musclecoder posted:You could use the __call() magic method, something along the lines of: Unfortunately I'm not sure if this will solve the problem as I have some methods that will need to search on two criteria - byUsernameAndPassword() for example. Then I have queries that will be much more complex. Could I perhaps use a switch statement to build the appropriate 'where' statement depending on which method is run? For example: php:<? class User { public function __call($method, $argv) { $db->select(_FIELDS_GO_HERE_); switch ($method) { case 'byUsernameAndPassword': $db->where('us.user_name', $argv[0]); $db->where('us.user_pass', $argv[1]); break; case 'byId': $db->where('us.user_id', $argv[0]); break; } $db->get('user us'); // etc etc } } ?> putin is a cunt fucked around with this message at 13:31 on Jun 5, 2012 |
# ? Jun 5, 2012 13:24 |
|
I've got a database of zipcodes that are both 5 and 9 digit formats, is there a way to either reduce all of the zips to 5 digits? I was looking into the substr function to allow for matching the first 5 digits and ignoring the last 4, I'd leave it as the 9 digit format but I don't think the people using this will know how to get their 9 digit zip.
|
# ? Jun 5, 2012 14:54 |
|
Black Noise posted:I've got a database of zipcodes that are both 5 and 9 digit formats, is there a way to either reduce all of the zips to 5 digits? Do they have the dash in between the two parts of the code? If they do, you could do SUBSTRING_INDEX(fieldname, '-', 1) to get only the first part of the zip.
|
# ? Jun 5, 2012 15:09 |
|
Null Set posted:Do they have the dash in between the two parts of the code? If they do, you could do SUBSTRING_INDEX(fieldname, '-', 1) to get only the first part of the zip. nope just the numbers
|
# ? Jun 5, 2012 15:29 |
|
Black Noise posted:I've got a database of zipcodes that are both 5 and 9 digit formats, is there a way to either reduce all of the zips to 5 digits? Can't you just do something like UPDATE zipcodes set zipcode= (SELECT SUBSTRING(zipcode, 0, 5) FROM zipcodes) Bear in mind I'm pretty bad at SQL ...Though now that I think about it that wouldn't work because the nested query returns > 1 result. Food for thought, though!
|
# ? Jun 5, 2012 15:51 |
|
Sab669 posted:Can't you just do something like SQL code:
|
# ? Jun 5, 2012 15:58 |
|
Sab669 posted:Can't you just do something like SQL code:
Edit: beaten! putin is a cunt fucked around with this message at 16:03 on Jun 5, 2012 |
# ? Jun 5, 2012 15:59 |
|
Black Noise posted:I've got a database of zipcodes that are both 5 and 9 digit formats, is there a way to either reduce all of the zips to 5 digits? If it's MySQL then do this: SQL code:
|
# ? Jun 5, 2012 15:59 |
|
Black Noise posted:I've got a database of zipcodes that are both 5 and 9 digit formats, is there a way to either reduce all of the zips to 5 digits? For your database query you can select zipcodes that are LIKE '12345%'
|
# ? Jun 5, 2012 15:59 |
|
Black Noise posted:I've got a database of zipcodes that are both 5 and 9 digit formats, is there a way to either reduce all of the zips to 5 digits? Please define your problem better; start with, are you wanting to update the DB, or to perform a re-presentation step on the data after a read from the DB? (as in leave the actual data alone, but always make a common format before working on the data in PHP?) are the zip codes stored as integers or strings? do you want them as integers or strings? in any case, in PHP the core of your answer is going to be substr($zip, 0, 5) with varying amounts of intval() and strval() around the place, depending on the input and output types you want.
|
# ? Jun 5, 2012 16:01 |
|
KuruMonkey posted:are the zip codes stored as integers or strings? do you want them as integers or strings? FWIW: US zip codes can start with zero. They should never ever be treated as or stored as integers.
|
# ? Jun 5, 2012 18:15 |
Gnack posted:Unfortunately I'm not sure if this will solve the problem as I have some methods that will need to search on two criteria - byUsernameAndPassword() for example. Then I have queries that will be much more complex. Could I perhaps use a switch statement to build the appropriate 'where' statement depending on which method is run? For example: I wouldn't do it like that. I would go with multiple constructors: code:
|
|
# ? Jun 5, 2012 18:49 |
|
Null Set posted:
Actually that ended up just deleting everything that is more than 5 characters, now the stranger thing is that when I set it to start after the 5th number it deletes the first 4 numbers Black Noise fucked around with this message at 20:15 on Jun 5, 2012 |
# ? Jun 5, 2012 19:05 |
|
Now this is a bit of a work around, but what if you just did a select with the substring, exported those results to a CSV, then threw the CSV in there over all the existing values. From the sounds of things, it sounds like this is a "one-time-only" problem and you'd need not to do it again.
|
# ? Jun 5, 2012 21:10 |
|
fletcher posted:I wouldn't do it like that. I would go with multiple constructors: The book Effective Java touches on this a bit and suggests you have multiple static constructors. Thus, User::byUsernameAndPassword() or User::byId(). You get the benefit of having a more expressive method name as well.
|
# ? Jun 5, 2012 21:16 |
|
Black Noise posted:
Use what I posted before. It seems the mysql substring is weird: SQL code:
Don't ask me why the index is starting at 1 like that, but when I was testing this on my own tables I had to do that to start at the root. It's probably somewhere in the MySQL docs, but *edit* Also, if you're ever unsure of what an update/delete query will do, test it out with SELECT's first to make sure you're doing what you wanna do.
|
# ? Jun 5, 2012 22:20 |
|
McGlockenshire posted:FWIW: US zip codes can start with zero. They should never ever be treated as or stored as integers. Shows what a Brit knows about zip codes! Looks like the chap is actually looking for an SQL answer anyway...
|
# ? Jun 5, 2012 23:07 |
|
fletcher posted:I wouldn't do it like that. I would go with multiple constructors: Hmm I see - the thing is, I want it to work more like musclecoder suggested and have static methods I can use to return User instances that match the parameters. The only real problem I'm having with that is where on earth do I put the list of field names so I'm not having to retype it every time? Can I access properties statically (does that even make sense)?
|
# ? Jun 6, 2012 00:08 |
|
Gnack posted:Hmm I see - the thing is, I want it to work more like musclecoder suggested and have static methods I can use to return User instances that match the parameters. The only real problem I'm having with that is where on earth do I put the list of field names so I'm not having to retype it every time? Can I access properties statically (does that even make sense)? With codeigniter you can add this as the top of the class. (This is more like your original approach) public static $selectStr = 'us.user_id, us.user_name, us.user_email'; then do $this->db->select(self::$selectStr); or make it a constant. or maybe a method named _setSelectStr() or whatever. It doesn't really matter. But I'd be hesitant to do __call() in CI, because of how it works. And things like new User() wont work out with it because you're not supposed to do that with CI since it binds models to $this->modelName->methodName() Also, I'm pretty sure you should be doing class User extends CI_Model {. That'll give you access to $this->db without having to call get_instance() all the time.
|
# ? Jun 6, 2012 00:26 |
|
Didn't they change to Model from CI_Model in 2.x?
|
# ? Jun 6, 2012 01:11 |
|
Looking for a little advice: I am working mostly on Android these days its been a while since i've written server side code that wasn't Java/Ruby. My small startup (about 8 developers) users PHP and Cake for our web services stuff. I saw some of the tutorials in the first post, but was wondering if anyway had a leaping off point for someone with a solid development background to get into php. Something like http://www.ruby-doc.org/docs/ProgrammingRuby/ but for PHP? Sidenote: Is Cake as bad as the OP suggests? These guys seem to be dedicated to its continued use (hence me learning php vs. trying to convert to something else).
|
# ? Jun 6, 2012 01:16 |
|
barbarianbob posted:With codeigniter you can add this as the top of the class. (This is more like your original approach) If I can keep the select list in a static property then maybe that will solve my problem. Thanks for the tip, I'll give it a go. As a disclaimer for the above - I have no formal education in OOP, everything I know has just been picked up along the way from using C++ and Java. That means I'm happy for people to point out any mistakes I'm making in terminology because some of the correct terms for things I'm not exactly clear on. revmoo posted:Didn't they change to Model from CI_Model in 2.x? putin is a cunt fucked around with this message at 01:43 on Jun 6, 2012 |
# ? Jun 6, 2012 01:40 |
|
Gimbal_Machine posted:
If by Ruby you mean Rails (MVC + ActiveRecord), then you know enough of the basics of Cake to get by (at least 1.2/1.3, I've yet to touch 2.x). Yes, the internals aren't the most amazing code ever written, but it's got strong support at it's base. Extensions/plugins to it aren't the most available, unlike Ruby and Gems. My opinion is it isn't bad to use. My only huge complaint about it as a user was it's decision to toss around associative arrays instead of objects. It takes a bit to get used to, in any language. Talking about PHP in general, read the language reference for a start. http://www.php.net/manual/en/langref.php PHP isn't hard, and it's docs aren't all that bad, given you search by keywords from Google.
|
# ? Jun 6, 2012 01:58 |
|
PHP's documentation is a weird thing - it's frustrating and tedious to find what you want, until you eventually learn their 'way' of doing things and then it becomes some of the simplest and comprehensive documentation I've ever read.
|
# ? Jun 6, 2012 03:55 |
|
Gnack posted:PHP's documentation is a weird thing - it's frustrating and tedious to find what you want, until you eventually learn their 'way' of doing things and then it becomes some of the simplest and comprehensive documentation I've ever read. Given I don't do much php, but I've never been let down by Googling "PHP <what I want to do>" and having their documentation be the first or second result, usually with what I want.
|
# ? Jun 6, 2012 22:24 |
|
Alright I'm feeling really stupid here. I installed aptana and wamp to use as a preview server, under run config I have everything pointing to where the project is stored and yet I always get "generic server doesn't support start". I have no issues manually typing the /localhost/blah/blah.php and getting that to work, I just have no clue how to get aptana to preview it automatically. This is the first time I've ever messed with php or aptana
|
# ? Jun 7, 2012 02:05 |
|
My problem with PHP's documentation is that it's not always immediately clear what version it's referring to, or even how performance intensive a certain recommendation might be. Check the coding horrors thread for more examples of how the 'default' implementations often are not the best ones.
|
# ? Jun 7, 2012 20:37 |
|
|
# ? May 19, 2024 17:10 |
|
The key to reading the PHP documentation is to just sit and read the first couple paragraphs of the page FOR COMPREHENSION and not be a tard who immediately scrolls to the examples at the bottom of the page. I can't tell you how annoyed I am by junior developers at my job who do that.
|
# ? Jun 8, 2012 19:55 |