PHP (AuraPHP router) - routing with more than one optional parameters - router

i have got a little problem in my auraphp router. For example i have this URL : oleje/134/motorove-oleje-pro-automobily/
But i can have this URl also : oleje/134/motorove-oleje-pro-automobily/oleje-shell
The "oleje-shell" part of URL is optional and i need to put behind this part one more optional parameter called "per_page". So i need something like : oleje/134/motorove-oleje-pro-automobily/35 or : oleje/134/motorove-oleje-pro-automobily/oleje-shell/35.
I hope, you got it.
Thanks for help.

2 options are coming to my mind.
Optional Params
$router->add('archive', '/oleje/134/motorove-oleje-pro-automobily{/oleje,number}');
Wild card Params
$router->add('wild_post', '/oleje/134/motorove-oleje-pro-automobily/')
->setWildcard('other');
// this matches, with the following values
$route = $router->match('/oleje/134/motorove-oleje-pro-automobily/oleje-shell/35', $_SERVER);
// $route->params['other'] = array('oleje-shell', '35')
In both cases you may want to check whether the one you got is string or number.
Hope that help!

Related

Trouble with poDoNotEncode option in TRESTRequest.AddParameter() method

I'm having trouble using the poDoNotEncode option in the TRESTRequest.AddParameter() method. I need to be able to post a request with a j_token header with a value that includes the '/' characters or else. For this need, I read everywhere that I can simply add poDoNotEncode to the options of the request parameters.
I tried several methods I found on the Internet to add a j_token header to my request:
var
RESTRequest : TRESTRequest;
RESTClient : TRESTClient;
Response : TRESTResponse;
begin
RESTClient := TRESTClient.Create('http://127.0.0.1:5000/')
RESTRequest := TRESTRequest.Create(nil);
try
RESTRequest.Client := RESTClient;
RESTRequest.Method := rmPOST;
RESTRequest.AddParameter('j_token', 'ga/ga', pkHTTPHEADER, poDoNotEncode);
//RESTRequest.Params.AddHeader('j_token', 'ga/ga').Options := poDoNotEncode;
//RESTRequest.Params.AddItem('j_token', 'ga/ga', pkHTTPHEADER, poDoNotEncode);
RESTRequest.Execute;
Response := RESTRequest.Response;
ShowMessage(Response.Content);
finally
RESTClient.Free;
RESTRequest.Free;
end;
end;
In this example, I used my own API to see the content of my request headers (here just j_token). Each and every method I tried (the commented ones) result with this:
Request headers : ga%2Fga
Meaning that the header I'm sending is url-encoded whether or not poDoNotEncode is specified.
Just to clarify, I'm working currently on a program developed by the company I work for. This software should use Delphi 10.3 Rio as its script language.
Maybe it can help, but when I try something like this:
RESTRequest.AddParameter('j_token', 'ga/ga', pkHTTPHEADER, [poDoNotEncode]);
I get this error:
RUNTIME ERROR : Impossible converting variant of type (Array Variant) to type (Integer) when evaluating instruction PushVar($0,$0,$0,$0, 'Result')...
And when I try something like this:
RESTRequest.AddParameter('j_token', 'ga/ga', pkHTTPHEADER, TRESTRequestParameterOptions.poDoNotEncode);
then I get this error:
Unknown identifier or variable is not declared : 'TRESTRequestParameterOptions'
I tried to be as precise as possible, because I'm completely stuck right now. If you need more precision, I'll try to answer as clearly as possible.
I've solved my problem. To provide a context, I have access to the archives of my company with every script they made. To learn delphi it helps a lot, and as I was looking at an example for the TRESTRequest.AddParameter() method i noticed that the 4th parameter for this method was a 0 like this :
RESTRequest.AddParameter('j_token',mytoken,pkHTTPHEADER,0);
So I looked on the internet to find what that 0 meant and i found out it was supposed to be an option for the parameter such as poDoNotEncode. I was still wondering why they replaced that with a 0 but I simply guessed it was to avoid an error if you don't put anything because our compiler wants the RESTRequest.AddParameter() method to have 4 parameters. So in the end i started doing the same until i needed my parameter to not getting encoded. But the poDoNotEncode option wasn't working. I tried to see what it would show inside a ShowMessage(poDoNotEncode); and it showed me a 0. So I decided as a test to put a 1 instead of poDoNotEncode like this :
RESTRequest.AddParameter('j_token',mytoken,pkHTTPHEADER,1);
And finally it worked, I have no idea why our software prefers using Integers instead of the real options names but if ever you stumble upon this problem, there is a high chance that you had the same weird definition of options.
Thank you all for your help !

How to correctly add a variable's value to parameters in Postman?

I'm learning Chrome Postman now and my issue now is:
I need to generate a new value of a parameter for each request.
So each request (I make a POST) must have a unique value of this parameter.
So far I thought to manage it with environment variables and I have done it like this:
I add a new environment variable with a unique value
I use this variable in the "value" field on a parameter
And it doesn't work - I get error 401 Authorization Required.
Seems that the error is not connected to the parameter at all but as soon as I change the parameter and manually input a unique data it works well!
So this will work for me:
Please suggest what I'm doing wrong here and advice how to do it right. Thanks!
Spent some more hours investigating I found my problem!
The problem is the value I put into a variable - it included ":" sign and this sign simply changed my URL.

Possible to isElementPresent(:id, "id") in watir webdriver

Using Watir Webdriver, I wanted to have a helper that would check for any element with given id. I may not know what type it is ( button or link or text). Can I just do
browser.Element(:id, id).exists
All of the examples i've found on google check against a specific element type, as in
browser.button(:id," ").exits
If there is a way, please share the syntax.
In Watir-Webdriver, I would use something like this:
browser.element(class: 'post-tag').exists?
which would find the watir-webdriver tag on this page and report that it exists. Note that I used the 1.9 syntax instead of the alternative syntaxes of:
browser.element(:class => 'post-tag').exists?
or
browser.element(:class, 'post-tag').exists?
As Dave points out, there is #element method. (You were wrong just in capitalization, it is not #Element.)
Since you are asking about accessing it using id attribute, try this:
browser.element(:id => id)
I've never gotten .exists? to work right on it's own.
What I've had to use in these cases has been to explicitly validate the "exist?"... like:
cf_checbox = #browser.text_field(:id=>'continue-ring', :value=>true).exists?
assert( cf_description == true)
without that explicit assertion, I would always get a "true" even when the value didn't exist.

Get statuscode text in C#

I'm using a plugin and want to perform an action based on the records statuscode value. I've seen online that you can use entity.FormattedValues["statuscode"] to get values from option sets but when try it I get an error saying "The given key was not present in the dictionary".
I know this can happen when the plugin cant find the change for the field you're looking for, but i've already checked that this does exist using entity.Contains("statuscode") and it passes by that fine but still hits this error.
Can anyone help me figure out why its failing?
Thanks
I've not seen the entity.FormattedValues before.
I usually use the entity.Attributes, e.g. entity.Attributes["statuscode"].
MSDN
Edit
Crm wraps many of the values in objects which hold additional information, in this case statuscode uses the OptionSetValue, so to get the value you need to:
((OptionSetValue)entity.Attributes["statuscode"]).Value
This will return a number, as this is the underlying value in Crm.
If you open up the customisation options in Crm, you will usually (some system fields are locked down) be able to see the label and value for each option.
If you need the label, you could either do some hardcoding based on the information in Crm.
Or you could retrieve it from the metadata services as described here.
To avoid your error, you need to check the collection you wish to use (rather than the Attributes collection):
if (entity.FormattedValues.Contains("statuscode")){
var myStatusCode = entity.FormattedValues["statuscode"];
}
However although the SDK fails to confirm this, I suspect that FormattedValues are only ever present for numeric or currency attributes. (Part-speculation on my part though).
entity.FormattedValues work only for string display value.
For example you have an optionset with display names as 1, 2, 3,
The above statement do not recognize these values because those are integers. If You have seen the exact defintion of formatted values in the below link
http://msdn.microsoft.com/en-in/library/microsoft.xrm.sdk.formattedvaluecollection.aspx
you will find this statement is valid for only string display values. If you try to use this statement with Integer values it will throw key not found in dictionary exception.
So try to avoid this statement for retrieving integer display name optionset in your code.
Try this
string Title = (bool)entity.Attributes.Contains("title") ? entity.FormattedValues["title"].ToString() : "";
When you are talking about Option set, you have value and label. What this will give you is the label. '?' will make sure that the null value is never passed.

Extjs Form Action Submit - Custom override?

Looking at the source code of Action.Submit, I'm trying to figure out where ext is appending the form's fields to the parameters.
Instead of sending each field as a separate parameter, I want to send something like:
formObj:{field1:value, field2:value}
Currently, each of those values are simply added to the parameter list along with any custom/baseParams.
Where are these formfields being added so that I can change this behaviour?
Thanks.
I'm not sure what your override needs to look like, but you'll probably want to look at Ext.Ajax.request() (in Core / Connection.js). When posting a form, the fields get serialized there, in this code block:
if(form = Ext.getDom(o.form)){
url = url || form.action;
serForm = Ext.lib.Ajax.serializeForm(form);
p = p ? (p + '&' + serForm) : serForm;
}
If you really want to track the process of creating parameter list, you can refer to Ext.form.Action.getParams.
You should also consider Ext.form.BasicForm.getValues as it returns exactly the result you want, the only problem is that you'll need to send it manually, e.g. using Ext.Ajax.request.