Sencha Touch 2.1 creating common class for AJAX request - sencha-touch

I have two doubts
1)I am using sencha touch 2.1 for my application. And i want to create a common class for AJAX request because i am going to call from many controllers. Now my question is inside which directory(like model,store,controller) the common class for AJAX will come.And how i refer that class in app.js
2)I want to set some configs like common url,text,etc for my app. How can i achieve this.
Thanks in advance.

1) Ext.Ajax is a singleton class of Ext.data.Connection, so you can already use it throughout your application without creating many instances.
2) As stated in the Ext.Ajax documentation, you can simply set Ext.data.Connection configs on the Ext.Ajax instance.
Ext.Ajax.setUrl('defaultUrl.json');
Ext.Ajax.request({}); // will use the above URL
You can get a list of all the available configs by looking at the Ext.data.Connection class reference.

Related

WebAPI endpoints without controllers

Is it possible to call WebAPI endpoints without extending the Controller base class? I have a background service (base class HostedService implementing IHostedService) in .Net Core. My class structure is already set in stone so I can't change the base class of my background services. But it would be a huge help if I could call url endpoints on them without actually having a separate controller.
Is this possible?
EDIT: My background services look exactly like this.
Why don't you use something similar to ValuesController in the link you provided?
You only have to create a new Controller with almost any logic, just calls to your Hosted service.

Create a Java Spring API Router

Im creating an API using Java and Spring. My question is, is there a standard way to organize the API routes into one file?
For example when creating an API using Express.JS there is one file, called the router, where all of the routes are declared and set up.
With Spring's annotation-based MVC framework it seems like the routes are scattered through various controllers. So if someone who didn't write the API needed to make changes to it they would be left searching through files to find the specific route.
Is there a standard practice or pattern that would create a central router? Im thinking about just creating a router class however I would then have to create instances of MANY classes in that router. It doesn't seem very clean.
XML configuration used to be the only way to do it, but if I remember correctly, the usual usage was to have one method per controller.
There's a fairly nice implementation of what you're looking for in the third-party springmvc-router project, which will let you configure your routes something like:
GET /user/? userController.listAll
GET /user/{<[0-9]+>id} userController.showUser
DELETE /user/{<[0-9]+>id} userController.deleteUser
POST /user/add/? userController.createUser

How does ASP.Net MVC resolve controllers?

I'm trying to build an asp.net mvc 4 application.
I want the application to encompass both a HTML site and a restful api, e.g.
www.mysite.com/MyDetails/
www.mysiste.com/api/users/{userid}/Details/
In the above example I would use 2 controller classes.
MyDetailsController which inherits from System.Web.Mvc.Controller
DetailsController which inherits from System.Web.Http.ApiController
I've also added a simple 'Users Route' to the WebApiConfig:
routeTemplate: "api/users/{userid}/{controller}/{id}
In my early testing it appears as though the following scenarios are invalid:
www.mysite.com/api/users/12345/MyDetails/
www.mysite.com/Details/
Both of those return a 404.
This is definitely a good thing but what I'm trying to find out is why doesn't it work?
Can I rely on it not working or is it just coincidence in my simple test?
I've read about people struggling to develop a single MVC app/project that encompasses both HTML and REST apis but the most common complaint seems to be you can't duplicate controller names and it still seems like you can't simply use a namespace to differentiate them.
In this example I've deliberately designed the class names to avoid any conflict so what other gotchas are waiting to trip me up?
Thanks,
Chris A
Check your routes file, should be Global.asax under RegisterRoutes. The MapRoute call should tell you everything you need to know for MVC routing. Keep in mind, the order of the routes is important: top routes take priority over the bottom. Web API uses the WebApiConfig class and MapHttpRoute call to configure routes.
Please ensure you have put a (MVC) route on top of the action you wish to hit of your controller, default action being index.
[System.Web.Mvc.Route("Help")]
public ActionResult Index()
{
ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
return View(Configuration.Services.GetApiExplorer().ApiDescriptions);
}
Code above will hit this action method (provided your controller is registered and derived either from apiController or Controller) in the following way:
http://localhost:54541/help inside your IISExpress.
To register please do the following:
In "global.asax.cs", you’ll need to add:
AreaRegistration.RegisterAllAreas();

Yii, using a module in main controller

Trying to use modules in Yii and want to get access from main controller (SiteController) for module's methods.
Create module with Gii, module name is Car.
Trying get access to method search in RequestController, module Car.
echo Yii::app()->Car->Request->search();
And Yii talks me
Property "CWebApplication.carhire" is not defined.
Does anybody knows how to get access to module's methods from another controllers?
Thanks
Your modules don't get put into the application scope. That is components that can be accessed via Yii::app()-> modules however are accessed via Yii::app()->getModule($moduleName)->.
This doesn't really help running an action on a controller though. It's difficult to get access too without entirely breaking the point of abstracting the module.
bool.dev's answer Here is the best methods i've seen if you really need too.
But the problem your having is likely pointing to an underlying problem with the structure of your site. If you need access to a module controller function somewhere else in your app, maybe it shouldn't be in the module?

YII how to call a function?

I'm in need of knowing how to call a PGSQL db stored procedure REQUIRING PARAMETERS
from a yii controller and passing it the parameters. Could please any one provide
me (maybe also the community) with a short tutorial including code snippets
about how to deal with this situation or direct me to sources where I can get the
information related to this topic from?
Thx in advance.
Are you trying to call the function from another controller?
In standard yii installation all controllers extend the Controller class as a base class. Therefore you can put the function in there and it will be accessible to all controllers.
protected/components/Controller.php
Or you could attach function by creating a behaviour:
http://www.yiiframework.com/doc/guide/1.1/en/basics.component#component-behavior