Comments (13)
I do change the default rules very often. So I agree it should be in the extended model.
from yii2-enhanced-gii.
In the extended model seems to make sense, but why not an option?
from yii2-enhanced-gii.
Extended Model is the best place
from yii2-enhanced-gii.
After I think about it, what if it's best that i generate on both model and the extended model merge parent rules with extended rules.. so if DB structure is changed, you don't have to type manually the validation of the new column..
what do you guys think?
from yii2-enhanced-gii.
For me, the difference between model and extended model is complicating the code. Every time I have to ask myself where to put and find things. Give an option to generate just one model with all code in it. Gone are the questions!
from yii2-enhanced-gii.
you should not type anything on the base model actually.. base models are for generated by gii only. so u don't have to move any code if you want to re-structure your tables.
on yii 1(i built the related CRUD generator too), i experienced that if i want to restructure the table, I have to backup my functions on the models before i re-generated the models
from yii2-enhanced-gii.
Well, sometime I have add new complex relations. If I put them in the extended model, I have two places with relations. Mmmm...
from yii2-enhanced-gii.
May I see your complex code as an example? Sent from my BlackBerry 10 smartphone on the 3 Indonesia network. From: Arjen MeijerSent: Senin, 15 Februari 2016 15.56To: mootensai/yii2-enhanced-giiReply To: mootensai/yii2-enhanced-giiCc: Yohanes CandrajayaSubject: Re: [yii2-enhanced-gii] Where to put model rules()? (#9)Well, sometime I have add new complex relations. If I put them in the extended model, I have two places with relations. Mmmm...
—Reply to this email directly or view it on GitHub.
from yii2-enhanced-gii.
Not complex, but nevertheless. A function to return the name of an id with the id attached. The same function I use everywhere for the select2 pulldown.
/**
* @return array with two fields
*/
public function getIdnameselection()
{
$spelvormen = Spelvorm::find()
->orderBy('spelvormname')
->all();
return ArrayHelper::map($spelvormen, 'spelvorm_id',
function($model, $defaultValue) {return $model['spelvormname'].' (id: '.$model['spelvorm_id'].')';});
}
from yii2-enhanced-gii.
Well, basically u dont type anything on the base models.. so that function
better be put on extended models..
On Mon, Feb 15, 2016, 16:15 Arjen Meijer [email protected] wrote:
Not complex, but nevertheless. A function to return the name of an id with
the id attached. The same function I use everywhere for the select2
pulldown./**
- @return array with two fields
*/
public function getIdnameselection()
{
$spelvormen = Spelvorm::find()
->orderBy('spelvormname')
->all();
return ArrayHelper::map($spelvormen, 'spelvorm_id',
function($model, $defaultValue) {return $model['spelvormname'].' (id: '.$model['spelvorm_id'].')';});
}—
Reply to this email directly or view it on GitHub
#9 (comment)
.
from yii2-enhanced-gii.
Yes, but than I have two places to store getFunctions. What (logically) differentiates the gii generated ones from the hand coded ones? I my head it are just getFunctions which should be in one place.
from yii2-enhanced-gii.
so it seems that your functions is for magic getter method. I always put that code on the extended model.
Logically it's the same, but be warned that your code will be rewritten if you change your DB structure & wants to re-generate the model.
you better move your getFunctions to extended models (manually) if you want to be in one place. (which will override your base model if you re-generate it)
from yii2-enhanced-gii.
Thanks for the explanation. That is what I am missing most in Yii2. I do not know WHY something is chosen, only that is chosen. Therefore, I can not re-think the decisions and make a correct extension of the thoughts.
from yii2-enhanced-gii.
Related Issues (20)
- In model generator tinyint create rules as string
- No results found. HOT 1
- Error when the instance of a model is created - Softdelete and Blameable Behavior HOT 1
- Custom Model Template HOT 1
- PHP version HOT 1
- wrong table name generated when table name has "_" in it HOT 1
- When I updated the master record, the child record on all related tables is soft deleted. HOT 1
- Generate migration column tinyint give error result
- Can't detect if in the model function beforesave the object is soft deleted HOT 1
- "Call to a member function getColumnNames() on null" HOT 1
- Open redirect in crud/default/views/_form.php HOT 2
- Models and CRUD generation in batch command HOT 1
- Edit Generator Code HOT 3
- PDOException: SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: HOT 2
- Model generation getRelations() bug
- Auto increment primary keys fails HOT 3
- bit, tinyint to boolean
- deletedByValueRestored is always 0
- HasMany: Update > valdiation error Message > update again >The object being updated is outdated. HOT 1
- Switch to twig or another templating engine? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-enhanced-gii.