-
Posts
15,266 -
Joined
-
Last visited
-
Days Won
431
Everything posted by requinix
-
1. .scroll(function) will "bind an event handler to the 'scroll' Javascript event". 2. .scrollTop() will "get the current vertical position of the scroll bar". 3. .css(object) will "set one or more CSS properties". All together, If you're not sure what that means, see it in action.
-
I phrased my post specifically so someone might mention that I was then going to follow up with "yes, that may hide the path to the image file itself, but the image is still accessible in some form at that URL so it doesn't help much". At least doesn't help with what it sounds like OP wants to do.
-
If PHP were to somehow obscure the path to the image, how would the browser know where to find it? Ultimately the browser needs to know because it's the one displaying the image. So no.
-
The command objects only live as long as they're needed. Once executed, or stored, or dealt with in whatever way you using them for, they're destroyed and cleaned up. They aren't persistent objects like your current Commands - ephemeral, created when needed and destroyed when handled. For example, this UpdateDatabaseCommand thing would go like 1. Client receives whatever request. 2. Client interprets request to mean to update the database according to whatever. 3. $command = new UpdateDatabaseCommand(with whatever information is needed to update the database) 4. $command gets executed or whatever. 5. You could unset($command) so then it gets cleaned up immediately, but really you can just ignore it and reassign whatever new object to that variable the next time through the loop. Six. Six of them. Probably could fit more in there.
-
Is it possible to change my username?
requinix replied to colap's topic in PHPFreaks.com Website Feedback
Turns out only the username is supported, not both as I thought. So that's the second lie I've told. I changed your username. -
And how are we supposed to know what's wrong?
-
Is it possible to change my username?
requinix replied to colap's topic in PHPFreaks.com Website Feedback
That can't be changed. The forum allows logging in with both the username and the display name. -
The as-a-service thing is irrelevant. This is a question of code design: either you a) Use one big class that can do every possible thing, requiring that it knows all possible information ahead of time, and call methods on it, class Commands { public function __construct($everything, $and, $the, $kitchen, $sink) { // ... } public function updateDatabase($foo, $bar, $baz) { // update the database } // public function doAnotherDifferentThing(???) { // ... // } } if (/* need to update database */) { $this->commands->updateDatabase(...); }orb) Use multiple small(er) classes that each do one specific thing, only needing whatever information is relevant at the time it's created, and have it be "executed" or something class UpdateDatabaseCommand implements ICommand { public function __construct($db, $foo, $bar, $baz) { // ... } public function /* ICommand:: */ execute() { // use $this->db to update the database } } if (/* need to update database */) { $command = new UpdateDatabaseCommand($this->db, ...); } // execute $command // updating the database requires that $db thing // you could hold onto it, or put it into a factory and hold onto that instead class DatabaseCommandFactory { public function __construct($db) { // ... } public function createUpdateCommand($foo, $bar, $baz) { return new UpdateDatabaseCommand($this->db, $foo, $bar, $baz); } } if (/* need to update database */) { $command = $this->dbcommandfactory->createUpdateCommand(...); } // execute $commandWhether you can perform multiple actions/commands per "request" doesn't actually affect the code. The difference comes in when you add Client into the mix. The big unified class wants the Client ahead of time but the Client needs the unified class too, while the single class you don't do it ahead of time. Of course now that I write it out, there's no particular reason why everything has to be set in the constructor. You're calling some method on Commands - pass the Client at that time.
-
Is it possible to change my username?
requinix replied to colap's topic in PHPFreaks.com Website Feedback
You can change your display name over here. -
There's really no need for slow and expensive regular expressions here. $modelName = substr($modelName, 0, -1);
-
$modelName[strlen($modelName) - 1] = "";Don't do that. You cannot use [] to remove characters - only replace. What the code above actually does is replace with a \0. I don't know what character you're trying to remove but I suggest looking at rtrim. [edit] The character is 's'. Which should be obvious given the code and output above. Eh.
-
a) Use multiple different Command objects, where each represents a distinct "command" and thus behaves differently, and provide a method in Client to change the loop frequency. public function changeFrequency($interval) { // ... } // switch(type of command to execute) { // case Change Frequency: // case Something Which Entails Changing Frequency: $command = CommandThatChangesFrequency($this); // ... // } $command->execute(); class CommandThatChangesFrequency implements ICommand { public function __construct(Client $client) { // ... } public function execute() { $command->changeFrequency($whatever); } }b) Same, except you keep the unified "Commands" thing and have to pass it every bit of data that could possibly be relevant. class Commands { public function __construct($foo, $bar, Client $client, $baz) { // ... } public function execute() { // switch (whatever the command is supposed to do) { // case command needs to change frequency: $this->client->changeFrequency($whatever); // ... // } } }c) Something else. Whatever you do, Client has a public method to change the polling frequency. Then you pass Client to whatever needs it. So just typical object-oriented programming.
-
.serialize is a function. You have to actually, you know, call it. And now your AJAX code and your PHP code don't agree. Are you working with JSON or HTML? Pick one.
-
Sounds like a Command. $obj1 doesn't need to read or write anything related to $obj2. Not directly. $obj1 interprets the response, constructs a "command" that contains the data necessary to perform whatever action is appropriate for the response, then passes it to $obj2 which executes the command. Or you say that $obj2 is itself the command and it gets executed directly (ie, $obj2->execute), cutting out the middleman. What happens from there depends on the command - maybe there's a return value, maybe not, whatever. Still too abstract though, and there is no single answer at this level. How about explaining why $obj1 needs to "modify" $obj2? And what is $obj2? What kind of range of possibilities of responses and actions is there, technically speaking?
-
1. You need to send the form data to AJAX2.php. data: $(this).serialize(),2. Your code is confused about what variable to use in the success callback. success: function(result) { alert(data); },3. The AJAX page needs to be consistent about whether it returns HTML or JSON. <?php header('Content-Type: application/json'); $variable = $_POST['var']; echo json_encode($variable); ?> <?php header('Content-Type: text/html; charset=utf-8'); $variable = $_POST['var']; echo '<p>' . htmlspecialchars($variable) . '</p>'; // for example ?>(your AJAX code expects JSON so obviously you need to use the former)
-
Prepared statements are the better way. Are you asking for the sake of hearing that answer repeated once more, or are you unsure how to deal with the variable number of placeholders?
-
Reading values from global variables is fine. Writing values is where the complications are, because it's not always easy to tell where a value comes from. If you only write in a small number of places (ideally one) then there's no problem. Put another way, don't just repeat what you hear without knowing why.
-
And a fourth: What's your question?
-
summary content before search keyword in text
requinix replied to artablog's topic in PHP Coding Help
You'll have to be more precise: you know what the output should be but why is it? What decisions did you make to arrive at that output? If you can explain what you did then you can express it as code. -
Re: large integers The largest possible result would be thirteen 9s = 2,541,865,828,329, which is beyond the limits of 32-bit PHP but still safe with 64-bit PHP, so as long as you're using a 64-bit build of PHP (eg, PHP 7) then you're okay. Otherwise it'll overflow to floating-point which uses approximations and could thus cause problems for you. Re: the loop To clarify, Jacques is saying that all you have to care about is the first (oldest) and last (newest) digits. Say you have four digits 7 1 7 6 -> 294: when you get the next number 5 then you can take 294/7 = 42 to factor out the first digit then 42*5 = 210 to factor in the new digit, rather than recalculating the full 1*7*6*5. Oh, and a quick optimization tip: if you encounter a 0 then you can skip forward thirteen places because all the multiplications during then will equal zero.
-
What you want to do is despicable. Are you saying the onbeforeunload works but the window.open does not? If it's not a problem with the code itself (eg, "URL" undefined or invalid) then it's likely that the browser is deliberately preventing that from happening.
-
Just [0-9] (or \d for short) will only match a single digit. If you want one or more then use +. Not sure how the "any number or exactly 900000" is supposed to work. Isn't 900000 a number too?