Access yii extension controller from another controller - yii

I am working on building API in YII controller, we have a comment module which is an extension . I want to access comment extension's controller so that I can use the same functionality to be accessed for my API instead of creating one.
Can anyone tell me how can i do it?
Actually I am working on making API for my website. Where I have created a controller for API and accessing other controllers for functionality already exists. There's a functionality that exist in comment-module in extensions. And i need to access that Controller in comment-module. Hope this cleared my question asked above. And I need to access this function via Ajax as well, if possible. But should be accessed via API controller.
Specifying in case any confusion. My requirements would be:
accessing methods of comment-module controller in only 1 method in API Controller. In order to make my functionality centeralized.
comment-module should itself keep working.
and work with API controller as well.
Note: Please explain your solutions as well, I am not a genius in yii like you.

Move common functions into treat or inherit controller from extension.

Related

Blazor Architecture

I am building a Blazor app and I have a need to reuse a bit of code that returns teh results of a linq query. My question is where do i put general code? What is the accepted place in the structure? I've got the following folders to choose from:
Authentication
Controllers
Data
Models
Pages
Services
Shared
and then once i've got this how do i call this public method? Is it enough that it is public or do i need to create a class variable of type x? Pretty basic stuff but i'm stuck.
I've puyt the methoid in once page component/class anmd then to use it elsewhere I 've created a new new instance of the class component so i can reference the method but is this the best way?
thanks
John
If the page you are reusing has html or css then use a .razor otherwise, use a .cs
Looking at your folder structure, MVC is not a good choice to architect Blazor apps as MVC is for Stateless and Blazor is not Stateless. There are several choices on how to accomplish getting data into a component, my favorite is DI.

Laravel 5.2 custom Middleware Levels on RESTful controllers

So from not using any framework at all, I finally forced myself to use LARAVEL 5.2 because i got tired of re-writing my own "framework" over and over again.
Anyway!
I think I'm pretty familiar with the Laravel framework and its dependencies now.
But now I need guidance on how to do this the smartest way.
I want to create a Middleware based on the companys DC.
Now every user is AUTHED by php's envget("username"); with a re-written "auth" middleware. So far, so good. (The server is not in the DMZ btw).
The thing is, our team thought that we should populate a database-table with all the users and give them a "Privilege-level", lets say 1 through 3 where 1 is "read only", 2 is "read+modify" and 3 is "read+create+modify" with our restful controllers. But.
since we use restful controllers i cannot really give them individual Middlewares? do I manually have to change every RESTful resource in my routes.php to make this happend? or can i do this another way? I would like to keep it as simple as possible.
Any suggestions?
Thanks in advance
(reserved for typsos )
#Tarre Tan
You can achieve this by adding your middleware in a parent controller's constructor.
All your controllers that require permissions will inherit from that controller.
You have one place to adjust your permissions if you want.
Hope this helps

How to get all the controllers from an arbitray module ID in Yii2

I'm working with Yii2 Advanced Template, so I have frontend, backend and commonspaces. What I need is to get all the controllers that a module, which I know the ID, has. I will call it from backend, but the module should be in any part, not necessarily in the same namesapace . Any help is welcome.

Is there a way to hook into the checkout event in Magento?

I'm creating a custom module that needs to hook in to the checkout success event in Magento.
What I need to do is this:
1). Once a custom has successfully checked out I need to present a special offer on the success page with a yes/no radio button and submit form. If they select yes I need to add their details to a custom grid in Magento backend that I have already created.
2). I then need to make an API call to a third party CRM using the POST method to authenticate and add the customers details to their billing system.
3). Upon completion there needs to be a way to update the Grid in Magento to change state from "pending..." to "accepted"
I have started the module but I just can't seem to find any clear documentation about making API Calls or POST requests from Magento that I'm beginning to wonder if this is actually possible?
I would be grateful if anyone knows of an extenion or documentation on how to do the above or if they know of a simpler solution...
If neccessary I can submit my module on Github as a reference if someone is able to assist me
Many thanks!
add a custom block to the checkout_onepage_success layout handle via XML. This block will contain your form.
in the controller that processes your form, you can use Zend_Http_Client to make the POST request to the third party API. Alternatively Zend_Rest_Client or Zend_Soap_Client or Zend_XmlRpc_Client if any of these protocols are used. All of those Zend packages are readily available in Magento.
this is just basic loading and updating models, you should already know how to do this

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!