get

Using getter/setter vs “tell, don't ask”?

前提是你 提交于 2019-12-03 14:33:40
问题 Tell, don't ask principle here is often pasted to me when I use getters or setters, and people tell me not to use them. The site clearly explains what I should and what I shouldn't do, but it doesn't really explain WHY I should tell, instead of asking. I find using getters and setters much more efficient, and I can do more with them. Imagine a class Warrior with attributes health and armor : class Warrior { unsigned int m_health; unsigned int m_armor; }; Now someone attacks my warrior with a

is_int() cannot check $_GET in PHP?

无人久伴 提交于 2019-12-03 14:30:29
Here is my code: <?php $id = $_GET["id"]; if (is_int($id) === FALSE) { header('HTTP/1.1 404 Not Found'); exit('404, page not found'); } ?> It always enters inside the if. is_int checks that the data type is an integer, but everything in $_GET will be a string. Therefore, it will always return false . In a pinch, you could cast to an integer and then check for != 0. $id = isset($_GET['id']) ? (int) $_GET['id'] : null; if (!$id) { // === 0 || === null header('HTTP/1.1 404 Not Found'); exit('404, page not found'); } But a more robust solution would involve some type of input string validation /

Passing Javascript array to PHP file [duplicate]

空扰寡人 提交于 2019-12-03 14:25:43
This question already has answers here : How do I pass JavaScript variables to PHP? (14 answers) Passing a JavaScript Value to a PHP Variable (With Limitation) (3 answers) So I know that Javascript is client-side and PHP is server-side and that complicates thing but I'm wondering how to go about doing this. I have an array in my javascript code (in a HTML file) and when the user hits my submit button I want the page to send over that array to my PHP page which will then take that date and put it into a SQL database. Is there a simple way to doing this? My array is declared like this var

Symfony 2 basic GET form generated URL

霸气de小男生 提交于 2019-12-03 13:38:58
问题 I have been trying to create an extremely basic symfony form (used for search functionality) with only one input. It uses GET method on submit. It seems to work as expected, however it generates an extremely ugly and unnecessarily long URL. I have been trying to 'clean' the URL up for a quite a while now, I was wondering if someone ran into the same problem and knows how to fix it? Form $form = $this->createFormBuilder($search) ->setMethod('GET') ->add('q', 'text') ->add('search', 'submit') -

Rules for naming POST/GET variables?

我的未来我决定 提交于 2019-12-03 11:31:35
Are there any rules one needs to follow when naming POST variables in a form or GET variables in a query string? Thanks- Wesley Murch TO answer the question literally, there really are no "rules" I'm aware of for naming $_POST and $_GET array keys in php. It's an array like any other. Take a look at this working example on Codepad : <?php $_POST['♠♣♥♦'] = 'value1'; $_POST['\'\'\'\''] = 'value2'; $_POST['<?php echo "Hello World"; ?>'] = 'value3'; $_POST[' '] = 'value4'; $_POST[''] = 'value5'; $_POST['@#$%^&*()'] = 'value6'; print_r($_POST); In the case of form input names, they just have to be

Problem with Android HTTP POST

南笙酒味 提交于 2019-12-03 10:11:15
I am using the below code to execute a HTTP POST request. The PostData is in the form of a String Sample of PostData: urn:marlin:broad band:1-1:registr ation-service:li nkAcquisitionurn: marlin:organizat ion:testpdc:devi ce-maker-x:clien tnemo:aa08a1:59e a7e8cfa7a8582http://docs.oasi s-open.org/wss/2 004/01/oasis-200 401-wss-wssecuri ty-utility-1.0.x sd" URI="urn:mar lin:core:1.0:nem o:protocol:profi le:1" wsu:Id="si gid0003" nemosec :Usage="http://n emo.intertrust.c om/2005/10/secur ity/profile"/>< /SOAP-ENV:Envelo pe> We are expecting a xml/soap response, instead we are getting an xml file

Elasticsearch GET request with request body

点点圈 提交于 2019-12-03 10:07:12
Isn't it against REST-style approach to pass a request body together with GET request? For instance to filter some information in Elasticsearch curl localhost:9200/megacorp/employee/_search -d '{"query" : {"filtered" : {"filter" : {"range" : {"age" : { "gt" : 30 }}},"query" : {"match" : {"last_name" : "smith"}}}}}' some tools are even designed to avoid request body in GET request (like postman) From the RFC : A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request. In other words,

How to get the request parameters using get in Spark Java framework?

爱⌒轻易说出口 提交于 2019-12-03 09:58:05
I'm new to sparkjava. I want to read my request params using spark java but I'm not able to find the correct syntax. please help me out. Below is my route method and the client call to it: my client request url: /smartapp/getDataViewModelConfig?collId=123' Route Method: get("smartapp/getDataViewModelConfig/:id", "application/json", (request, response) -> { String id = request.params(":id"); } The 'id' field is returning null here. Any suggestions as to what went wrong here? Laercio Metzner If you have to work with an URL like /smartapp/getDataViewModelConfig?collId=123 you have to deal with

Restrict POST Request The Server

烈酒焚心 提交于 2019-12-03 09:41:09
问题 I want to restrict all POST request that comes from other server via .htacces if they try to post any from other server thing they will get redirected to home page or 404 etc. I tried this <Limit POST> order deny,allow deny from all allow from 127.0.0.1 </Limit> Note:- GET request are allowed from all servers. Only to block POST requests. 回答1: That block will only prevent POST requests from hosts other than 127.0.0.1, and you will get a 403 Forbidden response. You could try using mod_rewrite

JavaScript get/set methods vs. standard methods

眉间皱痕 提交于 2019-12-03 09:34:36
问题 Why does JavaScript have two different ways to get/set object properties? Example: //implementation 1 var obj1 = { "x":1, get number() {return this.x}, set number(n) {this.x = n} } //implementation 2 var obj2 = { "x":1, getX: function(){return this.x}, setX: function(n){this.x = n} } Does one implementation style have advantages over the other? 回答1: Unlike normal methods, using get and set lets you operate on the object's properties directly (=== cleaner/lesser code) - while actually invoking