Giter Site home page Giter Site logo

Comments (13)

arjenmeijer avatar arjenmeijer commented on May 14, 2024

I do change the default rules very often. So I agree it should be in the extended model.

from yii2-enhanced-gii.

realmarkcross avatar realmarkcross commented on May 14, 2024

In the extended model seems to make sense, but why not an option?

from yii2-enhanced-gii.

chitwarnold avatar chitwarnold commented on May 14, 2024

Extended Model is the best place

from yii2-enhanced-gii.

mootensai avatar mootensai commented on May 14, 2024

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.

arjenmeijer avatar arjenmeijer commented on May 14, 2024

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.

mootensai avatar mootensai commented on May 14, 2024

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.

arjenmeijer avatar arjenmeijer commented on May 14, 2024

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.

mootensai avatar mootensai commented on May 14, 2024
                                                                                  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.

arjenmeijer avatar arjenmeijer commented on May 14, 2024

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.

mootensai avatar mootensai commented on May 14, 2024

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.

arjenmeijer avatar arjenmeijer commented on May 14, 2024

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.

mootensai avatar mootensai commented on May 14, 2024

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.

arjenmeijer avatar arjenmeijer commented on May 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.