Gii is fine, but templates for auto generation can be more versatile at least commented out most of possible overrides and description of them.
Gii is fine, but templates for auto generation can be more versatile at least commented out most of possible overrides and description of them.
Automatic code generation helped me learn how to use Yii, and is good for back-end/admin sections where you want the interface to remain consistent without particularly caring what the page looks like.
I do reckon, however, I relied on its existence a little too much at first. I mean, I’ve made a lot of sites over the years, and consider myself to be a competent programmer, but when I first used Gii I suddenly became lazy… Trying to do something outside the box just seemed like too much effort, and the first shot at my admin UI suffered from this. It was when I realised that I could customize the templates that I clued-up and found my coding-mojo (Cojo?) once more.
I see automatic code generation as being a progression from the PHP framework. Frameworks aren’t just pre-written code… That’s what Libraries are. The great thing about a framework is that it adds structure to my program so I know X piece of code should be in the model or Y really belongs in a controller. Automatic generation extends this structure into my code, and honestly I welcome this. As I can define the structure by editing/adding templates, I don’t really lose any control.
I honestly plan to put creating my own project-centric templates up there on my to-do list for the next big site I’m taking lead on. A little bit of standardisation goes a long way, especially when working in a team.
I’d agree fully with Ulten above about including commented-out overrides. I can think of many reasons that this would be a good addition, and not many why it wouldn’t.
It is essential for understanding Yii Basics as easy and fast as possible.
Very nice!
i can’t use gii because it requires the app to be online
my app is svn controlled, and the database can only be access from the server itself,
the directory of the live app can only checkout and not commit,
i only use yiic with a shell user on the server to generate my models,
the rest is faster done by hand, i barely use the default crud files anyway,
most of the time i create them for 1 model just as reference and examples to fall back too when i’m stuck somewhere
all my apps so far have required more complicated stuff then the auto generation can handle,
Automatic code generation is very good.
After the database created, I can generate the code for the first step, no need care about the tedious typing.
Hope the generation tool add more features in the future
If you want more, why not check out GII Extended (giix) ?
I like the generation of modules and the CRUD generation is a good starting point for your codes.
If asked for gii improvement, I would vote for:
feature to define your data structure with xml or yaml as in doctrine. You can define your data structure and fixtures in yaml and generate sql, models and the db very simple.
models generated in two files as BaseModel and Model (extending BaseModel), so you can overwrite your stuff in Model and regenerate BaseModel with gii when you have db changes (also inspired by doctrine)
but these are not essential, only convenience…
Marco
I think it’s “good to have” for model and controller generation. View generation is nice to have, but I end up making my own views 99% of the time that it’s really only good for some admin screens (and sometimes as a start to what ends up being the final view).
Obviously, it’s not essential (since the framework is well documented to create your own from scratch), but it’s a feature I very much like.
I always use customized Gii templates and sometimes customize them on the fly, just before code generation if I need some repetitive code in few models or controllers. With customized templates Gii is much more usefull, try it yourself.
Gii helps alot with speeding up the development process, I use it extensively and then customize/alter it for my needs. Ehancements to this tool will help alot.
Hardly ever use yiic webapp - it takes much more time to customize generated project than creating one from scratch.
Same with Gii. Scaffolding shouldn’t generate any actual application logic. I prefer Zend Framework’s approach: it generates all necessary directories/files/classes/methods (with empty bodies)/tests, but not logic.
Don’t you have a webserver running on your development machine?
I run LAMP on my production notebook. I can develop and test on my local machine. I can even visually walk trough my code with Netbeans and Xdebug.
After some major commits, a branch is pulled into testing. After testing is completed, the branch is pulled into production. Then development can merge with this branch. Db is updated with Db migration.
Currently working on an application which needs a quick-and-dirty backend, Gii is ideal for this project. I also use Gii to generate Models, mostly for the attribute labels.
For those that feel you should hand write your CRUD, I offer some points to think about. Gii will stop you from simple mistakes like typos that will slow you down, and you get the added benefit of not repeatedly re-inventing the CRUD wheel! You would be surprised how many developers will re-write large portions of code for CRUD because they wrote the last code specifically for tables/columns/views in the database associate with that code. Then to add to that horrible decision, they write similar but different code, giving dfferent results and behaving differently. This leads to more lost time in tracking down new SQL issue, timing issues, and a plethora of other small time consuming issues that could have been avoided by reusing code.
I know, that is the point of the framework… but then if one argues hand writing their own CRUD while using a framework they are not USING the framework
Please don’t take my opinions wrong, I agree that a developer should have the knowledge to do these tasks with out relying on a tool. They should have the knowledge to also read the code and track down issues if the tool fails. They just shouldn’t refuse a tool that rapidly accelerates their development time by removing the time it takes to do repetitive tasks, or tasks that take a long time by hand. Especially if that tool is tested and trustworthy like Yii/Gii!
Just my .02¢
I use it all the time, I’ve written a few of my own generators for Unit test skeletons and fixtures. I’ve customized my Model template. I don’t use it for Controllers and Views, I find it doesn’t save me time there.
Code generation is excellent, someone is always going to say “I like to do it the old fashion way!”, those people end up spending all day coding text editors in assembly . My time is worth $$$ I’d rather produce more software than prove I’m the best programmer.
Would you be able to share an example of how you created your generators for Unit Test Skeletons and Fixtures? If you are free to do that, I would think that it would be interesting to many people (at least I can say that for myself!).
For a large project, CRUD generation can save literally months of work. IMO you are in dreamland if you think hand coding CRUD is better.