Yii, using a module in main controller - module

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?

Related

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

Sencha Touch 2.1 creating common class for AJAX request

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.

StructureMap LifeCycle of UnRegistered Types

In structuremap you can control the lifeCycle of an object you register, normally some interface to a concrete type as follows:
x.For<IMyInterface>().Transient().Use<MyObject>();
So I can control the life cycle. However when resolving objects (Concrete) types that are not registered the life cycle defaults to what seems to be Transient().
This is obviously a convenient feature of structuremap as I surely dont want to register each concrete type.
However is there a way to override this life cycle without registration?
Furthermore it would be great if you can specify the life cycle of an object as an override much like:
ObjectFactory.With<SomeUnregisteredConcreteObject>().LifeCycleIs(...)
In such a case the life cycle would be modified for the next resolution to GetInstance
Any idea how any of this can be done?
You could create a child container & register the component:
var child = ObjectFactory.Container.CreateChildContainer();
child.Configure(config => config.For<SomeUnregisteredConcreteType>().Singleton());
var #object = child.GetInstance<...>();
I assume that the reason why you didn't want to register was because you didn't want the registration to hang around. I think this solves that problem.
I also don't know of built-in a way to specify a default lifecycle. However, I think it's probably possible using the IAutoMocker interface. You could probably browse through the code in that whole folder to figure out how to do it. The AutoMocking hooks into the container so that a component is requested that isn't registered, it calls into the IAutoMocker and gives it a chance to register a component. I imagine that you could use IAutoMocker to register components with a different default lifecycle.
If you succeed in this, I hope you send a pull request or write a blog post to share with the rest of us.

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

How to pass user details between objects in VB.net?

I'm redesigning an old VB6 application into VB.net and there is one thing I'm not sure on the best way to do.
In the VB6 application whenever we created a new instance of a component, we would pass in the user details (user name and the like) so we new who was performing the tasks. However, no that I'm redesigning I've created some nice class designs, but I'm having to add in user details into every class and it just looks wrong.
Is there a VB.net way of doing this so my classes can just have class specific details? Some way so that if my classes need to know who is performing a task, they can get the information themselves, rather than having it passed in whenever the objects are created?
You could put the details of the current user in a class that is accessible by all class instances of your application.
One place you could consider putting it is in the MyApplication class. You could also create a module and place it there.
Could you wrap the current user details into an object, and pass the object when you create the others? They would just keep a reference, and delegate to the user object for user-specific stuff.
That seems like the obvious way?