I am try create CRUD Through GII in YII Framework in modules folder .But there one option to change the CRUD path.
I looked around for this too. Hope this will help.
Create a module via Module Generator.
Register your module name in the config main.php (modules array)
Create a model via Model Generator. Fill in the fields and put this in Model Path : application.modules.[module-name].models
Create crud via Crud Generator. Fill in the fields and put this in Model Class: [module-name].models.[model-name]
Sorry the reference is in Indonesian.
Source
Create a module via Module Generator.
Register your module name in the config main.php (modules array)
Create a model via Model Generator. Fill in the fields and put this in Model Path : application.modules.[module-name].models
Create crud via Crud Generator. Fill in the fields and put this in Model Class: [module-name].models.[model-name]
add module name in Controller ID :[module-name]/[Controller-name]
module-name/user generates module-name/UserController.php.
If the application has an module-name module enabled,
it will generate UserController (and other CRUD code)
within the module module-name instead.
Maybe is useful to create controllers
like that you can get it your controller and view inside the module you want. Regarding the models, I am agree with previous answers.
Byee
Model Class: user_access.models.User
Controller ID: user_access/user
Model Class : application.modules.guestbook.models.Guestbook
Controller ID : guestbook/Default
Note : guestbook is my module name and i created crud directly inside guestbook folder using above path.
Related
I have solutions with layers(projects) like
Api-->Services-->DataAccess and Models project is common and referenced in all of them
now when I am trying to implement custom validation on one of the property in class in Models project, I am running in an issue that where to put the validator.
Validator has to access Service Layer to check if something exists in database.
if I put validator in API layer I can DI service but I cannot decorate the property with custom attribute since the property is in a class inside Models project and Model project is referenced in API project.
if I put validator in Models project then I cannot access Service Layer IContract as it is defined in Service layer and Service layer also reference Models layer.
any solution ?
I have a calculated field in a class used for photos which prepends a url to the filename, I want to be able to add a base url for the photos (which is to an azure storage account) which will come from the appsettings file.
Initially I created a strongly typed class to access the settings, and I can inject it just fine to say a service class, but how can I access this in a model class? Am I completely going in the wrong direction with this?
Thanks for any help!
When instantiating the model, you could inject your strongly typed settings class, as long as the model already has a dependency on that. Alternatively, you'd need to move the calculation of that field out of the model, or simply provide the base URL to the model from your service classes.
I have a MVC 4.0 Web API project and I have already added the model of my database to it so I have the files:
.edmx
.Context.tt
.context.cs
.edmx.diagram
I'm trying to figure out how to add a controller after I've created my entity framework model.
It's asking for the Model Class and Data context class.
I'm not sure what they are in my solution.
can anyone give me a hand?
It depends what you are trying to do...
1. you can create an empty controller and then you do not need to select the Model and Context. you write the Add/Edit/Delete functions yourself and their views.
2. you can create a controller with read/write action and views - this way you get these functions Add/Edit/Delete + views done for you automatically:).
The Context is (as I understand it) the reference to the database.
if you havent already you should add your model classes that you want to create as tables in the database to the YOUR-PROJECTNAMEContext.cs file under DAL folder. this will create the tables for you (if I didn't forget anything). you shoula add somethis like:
public DbSet<Note> Notes { get; set; }
where Note is your class for example and Notes is your table name.
now if you want to create a Controller for you notes class in the model and let MVC to do for you the ADD/Edite/Delete function and views than your model is: Note and Context is YOUR-PROJECTNAMEContext.
Hope it will help.
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?
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