-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
Store that information in a database instead.
-
When talking about URL rewriting you need to say precisely what URLs are you looking to be "virtual folders" and how should they map to PHP scripts. The "profil" (are you sure you don't want "profile"?) one is missing the part where it captures the ID in the URL. Presumably that's a number? RewriteRule ^profil/(\d+)$ profil.php?ID=$1 [L]The second one is very generic. What is it supposed to be used for? It should be more specific than simply "anything slash anything". Also, avoid [NC] when possible. URLs should be case-sensitive, or at the very least redirect to a particular cased version.
- 5 replies
-
- rewriterule
-
(and 1 more)
Tagged with:
-
$tip++ is shorthand for $tip = $tip + 1.
-
You can do the TICS/TACS logic in SQL quite easily with, say, the IF function. SELECT SUM(IF(TACS = 0, TICS, TACS)) AS sum FROM table...
-
And what did you say happens when you try to go to the URL that isn't working? Also, try adding an [R] to all of those rules to make the redirect happen externally - so you can see where you're being redirected.
-
1. "Queries"? Is this happening in a database? 2. Of the TACS that aren't zero, I assume they aren't the same values as in the TICS column?
-
Looks right so far. Can you post your entire .htaccess as-is? Maybe there's a conflict between rules. And when you say "doesn't work", what does that mean? What actually happens?
-
Or even cooler than magic terms like "color1" and "color3" would be class names that actually represent the underlying data. .games-highwinratio { color: green; } .games-evenwinratio { color: yellow; } .games-lowwinratio { color: red; }
-
How about posting the PHP code?
-
oracle765, you just posted your private API key on the Internet. Deactivate it and get a new one. Here's promoDescription. Try getting expediaPropertyId yourself. Array ( [HotelListResponse] => Array ( [HotelList] => Array ( [HotelSummary] => Array ( [0] => Array ( [RoomRateDetailsList] => Array ( [RoomRateDetails] => Array ( [RateInfos] => Array ( [RateInfo] => Array ( [promoDescription] => Save 10% foreach ($array["HotelListResponse"]["HotelList"]["HotelSummary"] as $summary) { echo $summary["RoomRateDetails"]["RateInfos"]["RateInfo"]["promoDescription"]; }
-
Did you notice that both of those RewriteRules are trying to redirect to the same place? I thought you wanted the first to go to treatments.php and not index.php...
-
What's the source XML?
-
Parse error: syntax error, unexpected T_LNUMBER
requinix replied to coingallery's topic in PHP Coding Help
Check your quoting. -
Help! [Syntax error: unexpected T_ENCLAPSED_AND_WHITESPACE
requinix replied to kir's topic in PHP Coding Help
What's the rest of the code before that? You've probably got an unclosed quote " earlier. -
I can't get it to produce any results.
-
Another way would be the alternate syntax to .on() which lets you attach an event handler to a parent element and have it trigger on the children. If you don't change the parent then the handler stays in place. $("#imagePickerWrapper").on("dblclick", ".newimageContainer label", function() {
-
Don't give them direct access to the file. Instead make them go through a download script of sorts. That script checks the logged-in user and the download requested and can approve (and send the file) or reject (show/redirect to an error message) the request. In your case you'd log somewhere the first time the user requests a file, then next time look in the log and reject because they've already downloaded it.
-
Php Inheritance, dynamic properties and new static() constructor
requinix replied to pepito's topic in PHP Coding Help
Maybe my use of the term "instance" is throwing you off. What I'm talking about is public class Parent { public Parent() { Console.WriteLine(this.GetType().Name); } } public class Child : Parent { public Child() : base() { } } Child c = new Child(); // Child, not ParentPHP behaves the same way. class ParentClass { public function __construct() { echo get_class($this); } } class ChildClass extends ParentClass { } $c = new ChildClass(); // ChildClassContinuing with that, class Config { public static function set($object, array $data) { echo get_class($object); foreach ($data as $key => $value) { $object->$key = $value; } } } class ParentClass { public function __construct(array $data) { Config::set($this, $data); } } class ChildClass extends ParentClass { public $name; } $c = new ChildClass(["name" => "pepito"]); // ChildClass echo $c->name; // pepito -
Php Inheritance, dynamic properties and new static() constructor
requinix replied to pepito's topic in PHP Coding Help
I assume that "findIdentity" and "getIdentity" are the same method, just inconsistently named in these posts? If you call User::getIdentity() then yes. If you create a subclass of User, say "ForumUser", and call ForumUser::getIdentity(), then it will return an instance of ForumUser - even though the code executing resides in (and was inherited from) the User class. Yes. Not only can static methods be inherited, they can also be defined in interfaces. The documentation doesn't mean that the method has to return a new IdentityInterface, which isn't possible anyways because it's an interface, but that whatever object it does return has to be an object of a class that implements, or has a parent class that implements, IdentityInterface. Yes to both.Because the method uses "new static" there are two possibilities for what it can return: a) A new User, which is fine because User implements IdentityInterface, or b) An object of a class that inherits from User, which is also fine because it inherits the implementation of IdentityInterface The term instance of can be a bit vague at times so I've tried to be more precise. If you say "an instance of User" meaning that get_class($object) == "User" then the answer is "not necessarily" because you could subclass User and then getIdentity() would return something of that class. However if you said the alternative "an instanceof User", which is what's happening here, then the answer would be yes. In this case it is because there is no subclass of User. Not quite the right explanation but the end result is correct. (I actually missed that those properties were defined when I said that the __get/set methods were "more likely" being used - they're not.) $object in configure(), which was the same $this as passed from the constructor, is an instance of the User class and thus $this->id will attempt to get or set the "id" property on that User instance. Directly. As for the $object->$name syntax, that touches on a more advanced subject, but the short explanation is that the code will attempt to get or set the property on the instance. So with $name = "id" then it will behave just like writing $object->id. The interface only requires that there (1) exist a method named "findIdentity" and (2) it has one parameter, and PHP will enforce it. Any class implementing that interface need only meets those two requirements - there is no requirement about how the method behaves or what, if anything, it returns (though the method's documentation gives clear indications to the developer as to what they should do). The reason is that using "static" keeps the door open regarding subclassing User (such as with ForumUser). If they just wrote "new User" then subclasses would have to reimplement getIdentity() since the parent's would always return a User object. Starting to lose me there. new static is kinda a factory already. It saves you from having to write out and manage class User ... { // now protected protected static $users = [...]; public static function findIdentity($id) { return isset(self::$users[$id]) ? new self(self::$users[$id]) : null; } } class ForumUser extends User { public static function findIdentity($id) { return isset(User::$users[$id]) ? new self(User::$users[$id]) : null; } } class AdvancedForumUser extends ForumUser { public static function findIdentity($id) { return isset(User::$users[$id]) ? new self(User::$users[$id]) : null; } }See how ForumUser and AdvancedForumUser have the exact same implementation of findIdentity()? The only difference between them is the sole reason why they have to exist separately: which class the method returns a new instance of. Without LSB and new static, User doesn't know about the ForumUser or AdvancedForumUser classes and so it can't create instances of them, thus it falls on the subclasses to figure that out. With LSB the entire thing can be reduced to class User ... { // back to private private static $users = [...]; public static function findIdentity($id) { return isset(self::$users[$id]) ? new static(self::$users[$id]) : null; } } class ForumUser extends User { } class AdvancedForumUser extends ForumUser { } -
Php Inheritance, dynamic properties and new static() constructor
requinix replied to pepito's topic in PHP Coding Help
PHP does not have static classes. Rather, static is used for static class members, static variables in functions, and late static bindings (LSB). It is the latter that is being used in this case. new static is a way of saying "create a new instance of whatever class was called when this method was invoked", which may make more sense if you consider that PHP does inheritance for static methods: if a parent class defines a static method then the child class inherits it too. Calling the static method on the child class will execute the one in the parent (if the child doesn't redefine it) and new static will then create an instance of the child class - where the method was called "from", in a sense. Compare that to new self which will always create an instance of the parent - where the method is defined. As mentioned above, LSB is the mechanism. Yes. And yes, that is what it is doing. PHP lets you define object variables at runtime, but it's not a good practice to get into. However it also lets you override property getting and setting when the properties don't exist, so more likely the yii\base\Object class does that and thus $object->property (which doesn't exist) will invoke the override and that function can do whatever it wants. (Often the value goes into an array of data.) You are correct in that $this behaves like it does in, like, every other OOP language: refers to the object instance of whatever class that may be. Meanwhile self refers to the class in which it is being used (regardless of inheritance), and of course there's also static with LSB. -
The HTML for a dropdown box looks like <select name="name for this dropdown here"> <option value="value 1">Label 1</option> <option value="value 2">Label 2</option> <option value="value 3">Label 3</option> </select>The value should probably be an ID number for each president, such as the key from $presidents. The label would be, of course, their name. Can you get that in place?
- 8 replies
-
- php
- intro programming
-
(and 1 more)
Tagged with:
-
Preg Replace Callback Function Replacing Content Twice
requinix replied to ShoeLace1291's topic in PHP Coding Help
If you went with method #1 then it should work. What's your parse_quote() look like now? -
What you have sure looks like it will display the number of downloads. Still not clear what Flash has to do with this though.
-
So what's your question?
- 8 replies
-
- php
- intro programming
-
(and 1 more)
Tagged with: