Yii Framework Forum: Code generators - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Code generators

#1 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,311
  • Joined: 17-January 09
  • Location:Russia

Posted 07 August 2011 - 11:57 AM

Currently we have two ways of generating code: yiic shell that's deprecated and Gii. Gii got a very warm welcome and is a really good tool. Still, in some cases it's preferred to use command line.

Problems
- Maintaining templates for these two methods is double amount of work.
- Command line code generation is deprecated but is still used by developers.

Solution
- Same templates for both cli and Gii.
- API to use these templates.
- Gii and cli using API.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 07 August 2011 - 08:27 PM

I never used yiic shell where Gii can offer the alternative.
What do you mean by "Still, in some cases it's preferred to use command line."?

I mean, isn't it enough just to remove those yiic commands that have their equivalents in Gii?

This post has been edited by softark: 07 August 2011 - 10:04 PM

0

#3 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,311
  • Joined: 17-January 09
  • Location:Russia

Posted 08 August 2011 - 07:01 AM

softark
1. Some developers are preferring CLI instead of UI.
2. If you want to re-generate models automatically, for example, at SVN/Git commit hook you'll need either CLI or API.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#4 User is offline   Dana 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 203
  • Joined: 18-February 10
  • Location:Florida, USA

Posted 08 August 2011 - 08:11 AM

I prefer to use the CLI for model generation, specifically because it creates the fixture and test data which the Gii tool has not done to date. It would be very troubling to lose that capability.

If there was a way to bring the two together so that they can share templates it would be wonderful.
2

#5 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 08 August 2011 - 08:25 AM

I see.

What about the modifications and/or additions that a developer has made to his customized Gii? Could they still be applicable to CLI?

Templates may be OK, but what if he has modified the UI and added some extra fields to it?
0

#6 User is offline   Say_Ten 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 17-September 10

Posted 08 August 2011 - 08:26 AM

I entirely approve of this suggestion. I haven't used the CLI in a while as we went with the fluffier system for consistency all round. I would like to see it brought up in terms of quality though as it's sometimes easier to work in for us command line commandos ;p
0

#7 User is offline   grigori 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 06-February 11

Posted 16 August 2011 - 12:23 PM

the web-based is better due to interactivity
for now it's just showing diff, but with cli you won't get this conveniently

it worth to concentrate on gii and improve the generators
0

#8 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 633
  • Joined: 29-November 08
  • Location:Paris, France

Posted 16 August 2011 - 05:25 PM

I use yiic to generate the Yii webapp skeleton (when creating a new project) or start unit test by one click from my Eclipse workspace. I find it convenient ...
8)
0

#9 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 604
  • Joined: 08-May 09

Posted 17 August 2011 - 01:20 AM

I always use yiic
0

#10 User is offline   migajek 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 15-November 09

Posted 19 August 2011 - 06:58 AM

Hi,
I was very disappointed when first saw "yiic" is deprecated.
I think nobody will argue that most of php developers use console anyway (for server maintenance etc).
As for me, console is more convenient, it's faster to type than to click and type, and is easier to extend (I'm using yiic shell for running my own commands for technical maintenance of php service - dropping cache, and so on).
Also, yiic is zero-configuration and doesn't need to be disabled after deployment.


My vote is for yiic
0

#11 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,336
  • Joined: 12-October 09
  • Location:Croatia

Posted 19 August 2011 - 08:35 AM

Yiic is not deprecated only code generation from command line...

we should differentiate this...

Yiic is still used for creating a new webapp and for various CLI commands...

In the beginning yiic was used to create models and CRUD, too... and that is the part that was deprecated in favor of the more flexible Gii...

So we are talking here only for this part if yiic or did I understood this wrong?

As for me - for the code generation I use Gii... and IMO we can remove the model and crud from yiic... no need to have it doubled as there is no way to offer or possibilities of Gii in yiic...
Find more about me.... btw. Do you know your WAN IP?
0

#12 User is offline   yiqing95 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 586
  • Joined: 27-December 10
  • Location:china

Posted 19 August 2011 - 08:36 AM

i often use gii ,even develop our own templates . but as samdark said the cli sometime is more useful to developer. we can write php or other language scripts to communicate with the cli , for example auto generate all CRUD controller and views for all models . you see someone is so lazy :lol: .

when develop application we should support both GUI and CLI interfaces to end client . GUI is for human beings, CLI is for program , these two interfaces should share the logic and data access layers. so the solutions samdark give is well. they can use api which is a intermediate layer to share the templates thus to reduce maintenance costs .
0

#13 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 19 August 2011 - 11:15 AM

I actually like both. :)
Would be nice if they could be made to make use of the same templates/code/whatever.

One thing that I'd like to have is a web-based interface to the migrate shell.
Sometimes you don't have shell access on a host.
A web based interface with diff view would be really neat. :)
"Less noise - more signal"
0

#14 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,311
  • Joined: 17-January 09
  • Location:Russia

Posted 19 August 2011 - 12:20 PM

mdomba
Yes, we're discussing code generation only.

jacmoe
Check my webshell extension.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#15 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 604
  • Joined: 08-May 09

Posted 19 August 2011 - 01:16 PM

I think, while creating a new app it is better to work with yiic.
my initial flow is the following:
  • yiic webapp
  • yiic migrate create install
  • edit database settings in config/main.php, config/console.php
  • yiic migrate
  • yiic shell for creating modules, models and cruds


this is really saving me a lot of time
0

#16 User is offline   migajek 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 15-November 09

Posted 22 August 2011 - 06:01 AM

ok, still voting for yiic for code generation.
Console is just way more convenient.
0

#17 User is offline   Psih 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 114
  • Joined: 30-June 10

Posted 23 August 2011 - 06:16 AM

Like the Gii, so I think they should be merged. Functionality should be the same. Just different interface :)
0

#18 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 23 August 2011 - 01:21 PM

I totally have that console thing...
CakePHP model/view/crud generation by the command-line is really awful.. <_<
No preview either..

I also like Giix instead of Gii.
"Less noise - more signal"
0

#19 User is offline   Psih 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 114
  • Joined: 30-June 10

Posted 25 August 2011 - 07:20 AM

Have to agree on Giix - it's far better (still has it's issues with the code quality - some undefined variables warnings and other stuff - will be fixing it and providing patches - but the functionality is good ).

The WEB part is great, especially the ability to preview what is actually generated and select the files you want (sometimes I need 1 or 2 files from CRUD generator, not all of them).

And what I really want, is ability to use some DB specific features like checking the box "Use MySQL specific features" witch will understand "ENUM" type fields and actually generate a rule like
array('field', 'in', 'range' => array('ENUM1', 'ENUM2, ..., 'ENUMN')

or date type fields.
That should be build-in from the start, but optional. Need one? Tick the checkbox (and maybe be able to define defaults in config).
I had a discussion with SamDark about adding DB specific code generating to Gii and the reasoning for not doing it is solid - we provide cross-db functionality. Totally understand the reason. But the reality is - how many people really write cross-db code? Some, yes. But not majority. So I think there has to be db specific code generation in Gii - just optional, not enabled by default (unless done in config). People will use it, and they will be happy for sure. And I'm 100% sure community will fill in the gaps with patches quite fast for every supported DB.
0

#20 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 25 August 2011 - 10:33 AM

View Postsamdark, on 19 August 2011 - 12:20 PM, said:

jacmoe
Check my webshell extension.

You are right.
And I did. :)

It's actually pretty simple, also without using the webshell extension:
	private function runMigrationTool() {
    	$commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
    	$runner = new CConsoleCommandRunner();
    	$runner->addCommands($commandPath);
    	$commandPath = Yii::getFrameworkPath() . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR . 'commands';
    	$runner->addCommands($commandPath);
    	$args = array('command', 'yiic', 'migrate', '--interactive=0');
    	$command = $runner->createCommand($args[0]);
    	array_shift($args);
    	ob_start();
    	$runner->run($args);
    	echo htmlentities(ob_get_clean(), null, Yii::app()->charset);
	}


The only problem is that web app doesn't do command map.
Which is needed for the migrate script if I want to use a custom migration class and/or use a table prefix for the migration table.

If a web application could have a command map, I'd be happy. :D
"Less noise - more signal"
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users