How to find YII routes from url - yii

I am new in Yii Framework. I am doing one small correction in Yii framework web app. Their third party Fax(Fax.de) API providers change something, I am trying to change the code, but I couldn't get the right file.
If the URL is www.example.com/paymentoption. What controller will work and where can I get Route folder?
Please help me...

in yii there is no route folder or file.
From Url you can simply find the controller named paymentoption. and in that you can find the method actionIndex which is called by Default

From documentation:
Routing involves two steps:
the incoming request is parsed into a route and the associated query
parameters; a controller action corresponding to the parsed route is
created to handle the request. When using the default URL format,
parsing a request into a route is as simple as getting the value of a
GET query parameter named r.
When using the pretty URL format, the URL manager will examine the
registered URL rules to find matching one that can resolve the request
into a route. If such a rule cannot be found, a
yii\web\NotFoundHttpException exception will be thrown.
Once the request is parsed into a route, it is time to create the
controller action identified by the route. The route is broken down
into multiple parts by the slashes in it. For example, site/index will
be broken into site and index. Each part is an ID which may refer to a
module, a controller or an action.
In this case, the link: www.example.com/paymentoption will use the controller PaymentoptionController and actionIndex, or it could be a module.
I recommend reading the documentation on the part of the Routing and Url manager: https://www.yiiframework.com/doc/guide/2.0/en/runtime-routing

Yii is a conventional based framework. That is, You should follow certain naming conventions to create your component.
For example. Your controller should be
SomenameController
Notice, above controller name has naming convention Controller adjoined to Somename
Here, You don't have folder to router, but controllers
//Get controller name
echo Yii::$app->controller->id
You can find a controller with that name in your controllers folder.

Related

Dynamic routes but not in the traditional sense

I wanted to know if there is a way to dynamically generate routes based on data from a database?
Currently, i am defining my routes in a routes file and then importing that into my vue project. Is there a way i can have specific configurations stored on a database such as the path, name, meta data and then when the application loads, depending on the auth level of the user, create routes for that user?
Reason why I'm asking to create and not use a pre-written route with params is because i want to give my users (at some point in the future) the ability to create their own pages from my system.
So just wanted to know from the community if there is a way to do this based on an axios call or something?
You can just use dynamic routing. To create new templates, code must be changed anyway.
I think technically you are still better off using a title parameter with a common prefix and just looking up that title. In theory it sounds nice to have a completely dynamic application where anyone can create any page... until someone decides to use "login" as the page name and override your own login component, making the app unusable.
That said, you can use router.addRoutes to dynamically add routes to your router. Create a router with the static routes (e.g. your homepage, your login page, your 404 page), then extend your router based on an api call.

Custom path for resource route in react-admin

Is there any way to specify custom paths for resources?
Example: <Resource name="User" path="/manageUsers" {...}>
If it's not possible "per resource", can we for example have all the CRUD pages be under a same basepath like: /crud/{/$resource.name} but keep the custom routes without that basepath.
Thank you very much.
EDIT #1
For context, we are building an admin panel that will have a lot of flows, basically step-by-step creation of resources. So I applaud the react-admin library for what it does (manage the CRUD part), but I want more flexibility in how the URLs are going to be.
I will need to have a section called /manageUsers/ that will have some data like a dashboard, and then the list could be /manageUsers/list/.
And then I may need another section called /customers/ that would list directly on that page.
EDIT #2
To give another use case, I'm trying to use graphQL as the dataProvider, and I had to rename all my resources since the rest API is using users where as the graphQL resource is User. So all my urls are now different!
I hope that makes it a bit more clear.
Is there any way to specify custom paths for resources?
No, this is not supported at the moment. One way to tackle this would be to use manageUsers as the resource name and translate it to User in your dataProvider.
I will need to have a section called /manageUsers/ that will have some data like a dashboard, and then the list could be /manageUsers/list/.
Definitely not supported by default either. However, you can replace the default Resource component with your own. It actually just creates routes for the resource inside a React Router switch. Note that you'll probably have to override the redirect prop of some components (such as Edit) because, when passed list, they expect the list to be at the resource root path.
I had to rename all my resources since the rest API is using users where as the graphQL resource is User
That's the dataProvider job to translate resources names into what your backend expect. Use resource names that make sense for your users (url wise).

How to return a relative URL from ASP.NET's GetUrlHelper()?

In an ASP.NET MVC 4 website I'm using Web API to return JSON-formatted resources including links for authorized actions (e.g., DELETE). To create these links I'm using the GetUrlHelper() extension method on the HttpRequestMessage...
_httpRequest.GetUrlHelper().Link( routeName, routeValues );
My concern is that the string returned from Link() is a fully qualified URL (it includes the https://example.com/...) when all I think I need is the relative URL (just the /my/resource). Currently, I've got a server problem where our production environment is adding http when it should be https, which doesn't work. I can fix that separately, but it raises the question, should I just supply a relative URL? And if so, is there a better way of getting a relative URL than trimming off the root part of the UrlHelper.Link()-generated URL?
Edit:
After consulting Richardson's & Ruby's meritorious RESTful Web Services, I believe more firmly that a relative URL is wholly appropriate here.
Does the PathAndQuery on Uri help you?
Example: (new Uri(_httpRequest.GetUrlHelper().Link("DefaultApi", new { controller = "Values", p1="abc" }))).PathAndQuery...this would give you like /my/resource?p1=abc

Consume my own REST api with Play Framework

So I am updating a Play 1.2.x application with has the following setup
- controllers
- api
- Documents // create, update, read, delete, list
... // more controllers
- web
- Documents // list, read, etc...
.. // more controllers
The controllers in the api package render data as Json which is used by mobile clients (Android, iPhone).
Now I want to have a plain simple html web app consuming the api. So how can I consume the API from the controllers in the web package?
My goal is to avoid rewriting the api controllers logic in the web controllers logic.
Thanks!
Reusing methods between controllers is not the best practice in my opinion. Shared behavior should be coded in the model and both controllers can then use the same model methods.
Nevertherless if you want to do so, you can extract shared behavior in a public method in your apis controllers wich you can annotate as "#Util" and then call this method from your web controller.
There are not many details in your question, so I do not know if it applies, but usually when I implement REST APIs I let them serve their answers in different formats (JSON and HTML, and if you want JSONP and XML for instance).
The main idea is just to
check the request to know what format is required: either using the accept content type, the url extension, or even a parameter (and some more about it)
pick the right template (or skip a template if you have already correctly built your Json object)
In play there are different ways to do the first part, eg. through your routes: Request Content-Type in Play! Framework for REST webservices ; there is a specific page on Play documentation about this.
But the most important part in this answer is the second point: you should use the same controller and the HTML template should be able to render your page with the very same data that is sent back as json (or maybe a little more)!
NB. if you need to customize things a little more you can access the request object in the controller, check what the requested format is, and act accordingly to return appropriate data using the appropriate template!

Automatic non-RESTful routes in Rails 3?

We have an app with a large number of non-RESTful, verb-oriented controllers. I remember that long ago, before Rails got the REST religion, you could get automatic routes and helpers for those. Is there any way to still do this? It's a pain to keep adding GETs every time we add an action, and our app (or perhaps our collective development brain) just doesn't lend itself to RESTfulness.
You can use the "magic route", I believe it's still in the routes file by default, but if you don't have it here it is:
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
You can still use a default route like this:
match ':controller(/:action(/:id))'
to match paths like
/monkey/play
/monkey/see/1
/monkey/hear/1
/monkey/eat/1