Newbie Code Generation Questions

I am considering Yii (coming from Cakephp)

In regards to Gii:

Does it analyze db tables to determine relationships (Has, BelongsTo, etc.) and construct models accordingly?

Can it automatically create pagination?

Does it add column header sorting in admin?

Is there a way to generate a whole site CRUD (all the tables, models, controllers, etc.) with one command?

Yes, it analyzes foreign keys and generates relations.

CRUD creates pagination, column header sorting and it can be done with one command.

OK, I looked and I looked but I did not see how to generate an entire site with one command or form (MVC with CRUD) from the database tables. Sorry if it is right under my nose. Could you point me to the whole site creation via Gii documentation?

Check Generating CRUD Code: http://www.yiiframework.com/doc/guide/quickstart.first-app

Thank you for responding samdark, but I am afraid I must be miscommunicating. I have used Gii as I am looking to convert a massive database from a project I did in Cakephp. But it seems tedious in Gii to type in the name of every table, then the model name etc. I am hoping that Gii can simply look at the database and BATCH process All the tables into MVCs and CRUD. This would be much more of a time saver. If my tables follow strict name conventions, then Gii should be able to do this. That is what I am looking for and I have not seen that batch option described in any of the documentation. In the future, it might be nice if Gii looked at the database, then generated a form with all the tables listed and asked me which I wanted to process along with various parameters and options (like tests).

So…can Gii batch process ALL my database tables into MVCs and CRUD at once?

Gii can’t. yiic shell can.

but it should :rolleyes:

I don’t think that it would difficult to add, but I’m REALLY new at Yii :-[

Yes I have Yii 1.1.2 installed and I followed the deprecated yiic instructions and it came up with errors. So is the yiic in 1.1.2 disabled in someway as Gii is supposed to take its place? I was hoping to load yiic up and check the help for any documentation on this "generate all" command. I did see in the change logs for last June that "New: Enhanced yiic shell model command to generate all models for the whole database (olafure, Qiang)". But otherwise no documentation. I have not checked the API though, but that should not be the place for general documentation.

yiic is not disabled in 1.1.2. What error do you have?

I am following the instructions on http://www.yiiframew…first-app-yiic. I got the following error about timezone, though my timezone is set correctly…

[john-petits-mac-pro-3:~/documents/htdocs/yiione2one] johnpetit% protected/yiic shell

<!DOCTYPE html PUBLIC

"-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>

PHP Error</title>

<style type="text/css">

/<![CDATA[/

body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}

h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }

h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }

h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}

p {font-family:"Verdana";font-size:9pt;}

pre {font-family:"Lucida Console";font-size:10pt;}

.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}

.message {color: maroon;}

.source {font-family:"Lucida Console";font-weight:normal;background-color:#ffffee;}

.error {background-color: #ffeeee;}

/]]>/

</style>

</head>

<body>

<h1>PHP Error</h1>

<h3>Description</h3>

<p class="message">

date(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Denver’ for ‘MDT/-6.0/DST’ instead</p>

<h3>Source File</h3>

<p>

/Users/johnpetit/Documents/htdocs/yiione2one/protected/views/layouts/main.php(47)</p>

<div class="source">

<pre>

00035: array(‘label’=&gt;‘Logout (’.Yii::app()-&gt;user-&gt;name.’)’, ‘url’=&gt;array(’/site/logout’), ‘visible’=&gt;!Yii::app()-&gt;user-&gt;isGuest)

00036: ),

00037: )); ?&gt;

00038: &lt;/div&gt;&lt;!-- mainmenu --&gt;

00039:

00040: &lt;?php $this-&gt;widget(‘zii.widgets.CBreadcrumbs’, array(

00041: ‘links’=&gt;$this-&gt;breadcrumbs,

00042: )); ?&gt;&lt;!-- breadcrumbs --&gt;

00043:

00044: &lt;?php echo $content; ?&gt;

00045:

00046: &lt;div id=&quot;footer&quot;&gt;

<div class=“error”>00047: Copyright &amp;copy; &lt;?php echo date(‘Y’); ?&gt; by My Company.&lt;br/&gt;

</div>00048: All Rights Reserved.&lt;br/&gt;

00049: &lt;?php echo Yii::powered(); ?&gt;

00050: &lt;/div&gt;&lt;!-- footer --&gt;

00051:

00052: &lt;/div&gt;&lt;!-- page --&gt;

00053:

00054: &lt;/body&gt;

00055: &lt;/html&gt;</pre>

</div><!-- end of source -->

<h3>Stack Trace</h3>

<div class="callstack">

<pre>

#0 /Users/johnpetit/Documents/htdocs/yiione2one/protected/views/layouts/main.php(47): date()

#1 /Users/johnpetit/Documents/htdocs/yii/framework/web/CBaseController.php(119): require()

#2 /Users/johnpetit/Documents/htdocs/yii/framework/web/CBaseController.php(88): SiteController-&gt;renderInternal()

#3 /Users/johnpetit/Documents/htdocs/yii/framework/web/widgets/CContentDecorator.php(78): SiteController-&gt;renderFile()

#4 /Users/johnpetit/Documents/htdocs/yii/framework/web/widgets/CContentDecorator.php(56): CContentDecorator-&gt;decorate()

#5 /Users/johnpetit/Documents/htdocs/yii/framework/web/widgets/COutputProcessor.php(45): CContentDecorator-&gt;processOutput()

#6 /Users/johnpetit/Documents/htdocs/yii/framework/web/CBaseController.php(207): CContentDecorator-&gt;run()

#7 /Users/johnpetit/Documents/htdocs/yii/framework/web/CBaseController.php(302): SiteController-&gt;endWidget()

#8 /Users/johnpetit/Documents/htdocs/yiione2one/protected/views/layouts/column1.php(7): SiteController-&gt;endContent()

#9 /Users/johnpetit/Documents/htdocs/yii/framework/web/CBaseController.php(119): require()

#10 /Users/johnpetit/Documents/htdocs/yii/framework/web/CBaseController.php(88): SiteController-&gt;renderInternal()

#11 /Users/johnpetit/Documents/htdocs/yii/framework/web/CController.php(689): SiteController-&gt;renderFile()

#12 /Users/johnpetit/Documents/htdocs/yiione2one/protected/controllers/SiteController.php(32): SiteController-&gt;render()

#13 /Users/johnpetit/Documents/htdocs/yii/framework/web/actions/CInlineAction.php(32): SiteController-&gt;actionIndex()

#14 /Users/johnpetit/Documents/htdocs/yii/framework/web/CController.php(300): CInlineAction-&gt;run()

#15 /Users/johnpetit/Documents/htdocs/yii/framework/web/CController.php(278): SiteController-&gt;runAction()

#16 /Users/johnpetit/Documents/htdocs/yii/framework/web/CController.php(257): SiteController-&gt;runActionWithFilters()

#17 /Users/johnpetit/Documents/htdocs/yii/framework/web/CWebApplication.php(320): SiteController-&gt;run()

#18 /Users/johnpetit/Documents/htdocs/yii/framework/web/CWebApplication.php(120): CWebApplication-&gt;runController()

#19 /Users/johnpetit/Documents/htdocs/yii/framework/base/CApplication.php(135): CWebApplication-&gt;processRequest()

#20 /Users/johnpetit/Documents/htdocs/yiione2one/index.php(12): CWebApplication-&gt;run()

#21 /Users/johnpetit/Documents/htdocs/yii/framework/cli/commands/ShellCommand.php(78): require()

#22 /Users/johnpetit/Documents/htdocs/yii/framework/console/CConsoleCommandRunner.php(62): ShellCommand-&gt;run()

#23 /Users/johnpetit/Documents/htdocs/yii/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner-&gt;run()

#24 /Users/johnpetit/Documents/htdocs/yii/framework/base/CApplication.php(135): CConsoleApplication-&gt;processRequest()

#25 /Users/johnpetit/Documents/htdocs/yii/framework/yiic.php(33): CConsoleApplication-&gt;run()

#26 /Users/johnpetit/Documents/htdocs/yiione2one/protected/yiic.php(7): require_once()

#27 /Users/johnpetit/Documents/htdocs/yiione2one/protected/yiic(4): require_once()

</pre>

</div><!-- end of callstack -->

<div class="version">

Warning: date(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Denver’ for ‘MDT/-6.0/DST’ instead in /Users/johnpetit/Documents/htdocs/yii/framework/views/exception.php on line 71

2010-05-19 14:13:08 <a href="http://www.yiiframework.com/">Yii Framework</a>/1.1.2</div>

It seems your PHP CLI is using php.ini that is different from the one used for web.

I am using MAMP with PHP 5.2.11 for my dev, but I am not sure if the terminal is using another older PHP installation for some reason. The only php.ini files I see are in MAMP (5 and 4). How do I set this?

php -c <php.ini-file>

See http://php.net/manual/en/features.commandline.php

The php the cli is using is version 5.3.1 from Darwin. If that is not good, should I point it to MAMP’s php?

Yes.

Thank you samdark for your time. I will mess around with this. But this would be so much nicer if Gii did this. Do you know if this capability is going to be added to Gii any time soon?

If it is being added to Gii, is there anyway I can beta test it?!

You can fill a ticket http://code.google.com/p/yii/issues/list so core team will know you need it. Can’t promise adding it very soon since there are a lot of things to do.

Thank you. I will fill out a ticket, but in case I ever to get yiic going, is the ‘generate all’ command in the help? If not, can you provide the command?

Yes, as I remember, it generated CRUD for DB tables.