How to create dynamic routing in phalcon? - phalcon

I have read the documentation of phalcon routing and cannot find the one like i needed.
/{param1}/{param2}/{param3}/controllerName/actionName/{param4}
Help me guys.

From docs:
/:params (/.) Matches a list of optional words separated by slashes. Only use this placeholder at the end of a route
In other hands you could rewrite their positions through apache/.htaccess.

Related

How do I enable query string in Cloudflare page rules?

I want to forward this URL
https://demo.example.com/page1?v=105
to
https://www.example.com/page1
It's not working if I set so:
But if I remove the ?v= part, it works:
Is there any way to include the ?v= part in this page rule?
The rule you mentioned works only for that exact URL: https://demo.example.com/page1?v=105. If it has any additional query parameter or even an additional character, eg https://demo.example.com/page1?v=1050, it won't match the rule.
If you need to use complicated URL matches that require specific query strings, you might need to use bulk redirects or a Cloudflare worker.

URL Parameters for API

I am trying to connect to this API endpoint, some parameters such as roomTypes and addOns require more parameters inside them. What should the URL be like?
Here is what I am trying, unsuccessfully:
https://api.lodgify.com/v2/quote/308200/?arrival=2020-10-02&departure=2020-10-07&propertyId=308200&roomTypes=[Id=373125, People=5]&addOns=[]
See image of Documentation
The correct format of parameters are as following:
https://api.lodgify.com/v2/quote/{PropertyID}?arrival={DATE}&departure={DATE}&roomTypes[0].id={RoomID}&roomTypes[0].people={PEOPLE}
It seems like you have space (white space) between Id and People in your URL, an URL must not contain a literal space

Recursive/Exploded uri variable with restlet

Does Restlet support exploded path variable (reference to URI Template RFC)?
An example would be /documents{/path*} where path can be for example "a/b/c/d/e".
This syntax doesn't seem to work with Restlet.
I'm creating a folder navigation api and I can have variable path depth, but I'm trying to have only one resource on the server side to handle all the calls. Is this something I can do with Restlet? I suppose I could create a custom router but if there is another way to do this I would like to know.
Thanks
It is possible to support this using matching modes.
For example:
myRouter.attach("/documents{path}",
MyResource.class).setMatchingMode(Template.START_WITH);
Hope this helps!
I'm doing the following
myRouter.attach("/documents/{path}", MyResource.class).setMatchingMode(Template.START_WITH);
Now I do get inside the resource GET method, but if I request the value of the path variable, I only get the first part (for example, /documents/a/b/c, path returns "a".) I use getRequest().getAttributes().get("path") to retrieve the value. Am I doing something wrong ?
Mathieu

How can I use a permalink containing a slash in a named route in Rails 3?

I followed Ryan Bates screencast of how to use permalinks in a Rails application. Unfortunately I am stuck with an issue when some of my permalinks contain slashes. Is there anything that I can do in the controller to encode those on the fly, or do they need to be encoded in the database?
You can use Rack::Utils.escape to return a clean, friendly URI. For instance:
Rack::Utils.escape("This/is/not/a/good/url")
will return
"This%2Fis%2Fnot%2Fa%2Fgood%2Furl"
and
Rack::Utils.unescape("This%2Fis%2Fnot%2Fa%2Fgood%2Furl")
converts it back to the original string:
"This%2Fis%2Fnot%2Fa%2Fgood%2Furl"
You'll have to wire those methods into the find methods in the controller, but should work out for you.
To generate permalinks that are safe, use something like this. It will create a 4 character long, url safe permalink and check to make sure there are no duplicates.
def create_permalink
loop do
self.permalink = SecureRandom.urlsafe_base64(4).downcase
break permalink unless ModelName.find_by_permalink(permalink)
end
end

Are colons allowed in URLs?

I thought using colons in URIs was "illegal". Then I saw that vimeo.com is using URIs like http://www.vimeo.com/tag:sample.
What do you feel about the usage of colons in URIs?
How do I make my Apache server work with the "colon" syntax because now it's throwing the "Access forbidden!" error when there is a colon in the first segment of the URI?
Colons are allowed in the URI path. But you need to be careful when writing relative URI paths with a colon since it is not allowed when used like this:
<a href="tag:sample">
In this case tag would be interpreted as the URI’s scheme. Instead you need to write it like this:
<a href="./tag:sample">
Are colons allowed in URLs?
Yes, unless it's in the first path segment of a relative-path reference
So for example you can have a URL like this:
https://en.wikipedia.org/wiki/Template:Welcome
And you can use it normally as an absolute URL or some relative variants:
Welcome Template
Welcome Template
Welcome Template
But this would be invalid:
Welcome Template
because the "Template" here would be mistaken for the protocol scheme.
You would have to use:
Welcome Template
to use a relative link from a page on the same level in the hierarchy.
The spec
See the RFC 3986, Section 3.3:
https://www.rfc-editor.org/rfc/rfc3986#section-3.3
The path component contains data, usually organized in hierarchical
form, that, along with data in the non-hierarchical query component
(Section 3.4), serves to identify a resource within the scope of the
URI's scheme and naming authority (if any). The path is terminated
by the first question mark ("?") or number sign ("#") character, or
by the end of the URI.
If a URI contains an authority component, then the path component
must either be empty or begin with a slash ("/") character. If a URI
does not contain an authority component, then the path cannot begin
with two slash characters ("//"). In addition, a URI reference
(Section 4.1) may be a relative-path reference, in which case the
first path segment cannot contain a colon (":") character. The ABNF
requires five separate rules to disambiguate these cases, only one of
which will match the path substring within a given URI reference. We
use the generic term "path component" to describe the URI substring
matched by the parser to one of these rules. [emphasis added]
Example URL that uses a colon:
https://en.wikipedia.org/wiki/Template:Welcome
Also note the difference between Apache on Linux and Windows. Apache on Windows somehow doesn't allow colons to be used in the first part of the URL. Linux has no problem with this, however.