YII how to call a function? - yii

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

Related

What is the correct way to use authorization policy class to authorize access to an index page in cakephp4?

I developed a few cakephp3 apps, and now I'm learning how to use cakephp4. I'm trying to centralize all my authorization logic in the *Policy classes. I have a situation where a user wants to access a entity/index page, and I want to validate if he can access this index page by doing some queries.
So right now I'm using $this->Authorization->authorize($this->Entity->newEmptyEntity()); in the controller, in order to be able to access an EntityPolicy->canIndex() method. Is there a more elegant way to do it, to call a policy method without an instance of the entity?
After that, in order to be able to run my queries, I'm using the ModelAwareTrait in the class, and querying data in a similar way that I do in controllers. Is there a better approach?
Send the entity itself. For example, if you are using the Articles controller
$this->Authorization->authorize($this->Articles);
$this->Authorization->can($this->Articles,'index')
While declaring the canIndex() method normally in your Policy.
My solution was somewhat different (and easier I guess)
//In my ProjectController.php
public function index()
{
$project = new Project();
$this->Authorization->authorize($project);
}
this way I don't have to do a useless query (I just create an empty Project object), but at the same time I can check the user attributes.
In my case the solution proposed by #eos (above) didn't work, because calling
$this->Authorization->authorize($this->Projects);
lead to an unwanted result.

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.

Spine.js have updateAttributes include new attributes

It seems that Spine's Model.updateAttributes only updates attributes, and does not create new ones in case you supply any.
In my usecase, I have a controller that creates part of the attributes. Then through an Ajax request the server responds with the full object, and I want to update the model instance living in Spine with the additional variables.
For example, I have a model with attributes: name, date_created. Through the controller a user instantiates an object providing only the name. An Ajax request notifies the server which in turn responds with a name and a date_created. This date_created should then be added to the user's model.
Model.updateAttributes doesn't work, and I wouldn't be too fond of deleting the object and creating a new one - that just seems as too much overhead. I could provide default values for variables that are not set upon creation, but that also has a negative side. I guess what I'm looking for is a method that could be called Model.createOrUpdateAttributes. Can anybody recommend a way to achieve this? Thanks!
I might haven't fully understood your usecase, but I'll try to answer.
You need to declare whatever attributes a type of a model has with the configure class method. This declaration helps various model function to do their job later.
After you declare all the attributes you need, you can create model instances with any of the previously declared attributes.
You don't have to provide values for all the declared attributes.
After the ajax call returns, the date_created will be set on your model instance. Until this happens it will be just undefined.
If this solution still can't work for you, please describe why, and I'll gladly try to help.

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?

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?