How to parse the Url which in the format as shown
http://localhost/CorrectCodeToDeploy/healthkatta/index.php?r=site%2FArticle%2F2013%2F07%2F13%2FDisadvantages-of-smoking-51e12690a5a58
Want to get rid of the special characters %2Fand put / instead . I have shared a link of an article to facebook
but when i access this link from facebook it comes in the format as mentioned above and the content is not properly accessed in Yii.How can i write the pattern to access this kind of url in yii
Maybe you can directly decode your $_GET in your index.php file, something like:
$_GET = array_map('urldecode', $_GET);
Please be aware the above doesn't work with nested arrays, so you need to create a more in depth recursive function like (not tested though) :
function urldecodeArray($strArr){
if (!is_string($strArr) && !is_array($strArr)) {
return $strArr;
}
if(is_string($strArr)) {
return urldecode($strArr);
}
foreach ($strArr as $key=>$value) {
$strArr[$key] = urldecodeArray($value);
}
return $strArr;
}
$_GET = urldecodeArray($_GET);
You can just to use urldecode() function
Related
I use Yii2 forms and after submit my URL looks like:
http://example.com/recommendations/index?RecommendationSearch%5Bname%5D=&RecommendationSearch%5Bstatus_id%5D=&RecommendationSearch%5Btype%5D=0&RecommendationSearch%5Bcreated_at%5D=&sort=created_at
As you may seem each parameter contains form name RecommendationSearch. How to remove this RecommendationSearch from parameters in order to get URL url like the following:
http://example.com/recommendations/?name=&status_id=&type=0&created_at=&sort=created_at
You need to override formName() in your RecommendationSearch model to return empty string:
public function formName() {
return '';
}
I'm trying to pass two parameters, one of which is an email address.
routes (also tried (:any))
Route::any(
'user/confirm_request/(:any?)/(:any?)', array(
'uses' => 'user#confirm_request'));
controller (also tried post_confirm_request())
public function get_confirm_request($email, $term)
{
//do stuff
}
Ultimately, all I'm trying to do is hit that route and send an email to a user with those two parameters. But I keep getting a 404 error. The email gets encoded and the route looks like this:
/email%40gmail.com/someString
I'm able to take out %40 and it works just fine (just gives me an error for the sendmail).
Why would the %40 be throwing a 404 error? Could it be a Laravel thing?
One solution would be to pass the email as a url parameter.
First, remove the second argument from the route. (You could also remove both if needed.)
Route::any('user/confirm_request/(:any?)', array('uses' => 'user#confirm_request'));
Then append the email to the action url, something like this..
$url = URL::base() . '/user/confirm_request?email=' . $email;
Then in your controller, you can grab that data.
public function get_confirm_request()
{
$email = Input::get('email');
}
I'm learning aspnet mvc 4 web api, and find it very easy to implement by simply returning the object in the apicontrollers.
However, when I try to return value types such as bool, int, string - it does not return in JSON format at all. (in Fiddler it showed 'true/false' result in raw and webview but no content in JSON at all.
Anyone can help me on this?
Thanks.
Some sample code for the TestApiController:
public bool IsAuthenticated(string username)
{
return false;
}
Some sample code for the jQuery usage:
function isAuthenticated(string username){
$.getJSON(OEliteAPIs.ApiUrl + "/api/membership/isauthenticated?username="+username,
function (data) {
alert(data);
if (data)
return true;
else
return false;
});
}
NOTE: the jquery above returns nothing because EMPTY content was returned - however if you check it in fiddler you can actually see "false" being returned in the webview.
cheers.
Before your callback function is called, the return data is passed to the jquery parseJSON method, which expects the data to be in the JSON format. jQuery will ignore the response data and return null if the response is not formatted correctly. You have two options, wrap you return boolean in a class or anonymous type so that web api will return a JSON object:
return new { isAuthentication = result }
or don't use getJSON from jQuery since you're not returning a properly formatted JSON response. Maybe just use $.get instead.
Below is a quote for the jQuery documentation:
Important: As of jQuery 1.4, if the JSON file contains a syntax error,
the request will usually fail silently. Avoid frequent hand-editing of
JSON data for this reason. JSON is a data-interchange format with
syntax rules that are stricter than those of JavaScript's object
literal notation. For example, all strings represented in JSON,
whether they are properties or values, must be enclosed in
double-quotes. For details on the JSON format, see http://json.org/.
Using Restlet 2.1 for Java EE, I am discovering an interesting problem with its ability to handle attributes.
Suppose you have code like the following:
cmp.getDefaultHost().attach("/testpath/{attr}",SomeServerResource.class);
and on your browser you provide the following URL:
http://localhost:8100/testpath/command
then, of course, the attr attribute gets set to "command".
Unfortunately, suppose you want the attribute to be something like command/test, as in the following URL:
http://localhost:8100/testpath/command/test
or if you want to dynamically add things with different levels, like:
http://localhost:800/testpath/command/test/subsystems/network/security
in both cases the attr attribute is still set to "command"!
Is there some way in a restlet application to make an attribute that can retain the "slash", so that one can, for example, make the attr attribute be set to "command/test"? I would like to be able to just grab everything after testpath and have the entire string be the attribute.
Is this possible? Someone please advise.
For the same case I usually change the type of the variable :
Route route = cmp.getDefaultHost().attach("/testpath/{attr}",SomeServerResource.class);
route.getTemplate().getVariables().get("attr") = new Variable(Variable.TYPE_URI_PATH);
You can do this by using url encoding.
I made the following attachment in my router:
router.attach("/test/{cmd}", TestResource.class);
My test resource class looks like this, with a little help from Apache Commons Codec URLCodec
#Override
protected Representation get() {
try {
String raw = ResourceWrapper.get(this, "cmd");
String decoded = new String(URLCodec.decodeUrl(raw.getBytes()));
return ResourceWrapper.wrap(raw + " " + decoded);
} catch(Exception e) { throw new RuntimeException(e); }
}
Note my resource wrapper class is simply utility methods. The get returns the string of the url param, and the wrap returns a StringRepresentation.
Now if I do something like this:
http://127.0.0.1/test/haha/awesome
I get a 404.
Instead, I do this:
http://127.0.0.1/test/haha%2fawesome
I have URLEncoded the folder path. This results in my browser saying:
haha%2fawesome haha/awesome
The first is the raw string, the second is the result. I don't know if this is suitable for your needs as it's a simplistic example, but as long as you URLEncode your attribute, you can decode it on the other end.
Currently Im trying to use elliots twitter library for CI at http://www.haughin.com/code/twitter/ after installation, it went well. the source code worked well..
Then I try to add code at index() function which is like this :
function index()
{
echo 'hi there';
$user = $this->tweet->call('get', 'account/verify_credentials');
$dec = json_decode($user);
}
I tried to decode json by using json_decode() function but it return error
json_decode() expects parameter 1 to be string, object given
This is my first time working with json..
Is there something I missed out ?
Thank you..
You should juggling that object into string type...
$user = (string) $this->tweet->call('get', 'account/verify_credentials');
$dec = json_decode($user);
It doesn`t need any variable convertion.
just access object directly like $dec->username