Help test gii: a web-based code generator

while generating a model, i got this exception(r2008):




CException

Description


Property "ModelCode.controller" is not defined.

Source File


C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\yii\dev\framework\gii\generators\model\ModelGenerator.php(9)


00001: <?php

00002: 

00003: class ModelGenerator extends CCodeGenerator

00004: {

00005:     public $codeModel='gii.generators.model.ModelCode';

00006: 

00007:     public function getSuccessMessage($model)

00008:     {

00009: $link=CHtml::link('try it now', Yii::app()->createUrl($model->controller), array('target'=>'_blank'));

00010:         return "The controller has been generated successfully. You may $link.";

00011:     }

00012: }






Hello,

I got this message:

Error 403

You are not allowed to access this page.

I’m accessing from http://localhost/myp...index.php?r=gii and I got that message, however, I tried using http://127.0.0.1/myp...index.php?r=gii and everything worked ok.

I resolved this problem adding ipFilters => array(’::1’,‘127.0.0.1’) to Gii Configuration.




        'modules'=>array(

                'gii'=>array(

                        'class'=>'system.gii.GiiModule',

                        'password'=>'password',

                        'ipFilters'=>array('127.0.0.1','::1'),

                ),

        ),



I’m testing Gii with last Yii svn version, PHP 5.3, Apache 2.2, Ubuntu Server 10.04 Beta 1.

Best regards.

Hi Qiang,

first impressions … looking good.

But, I got this error:


CException


Description


CCodeForm does not have a method named "getSuccessMessage".

and getErrorMessage.

Was able to hotfix this in CCodeForm:


	public function getErrorMessage(){

	    return "tbd";

	}

	public function getSuccessMessage(){

	    return "tbd";

	}

Then I was able to create the CRUDs, after adjusting the file permissions.

In phundament they’re not really working for me at the moment, because I do not have the correct layout.

I have to check this with yii skeleton again.

Same issue, as I mentioned per e-mail. It would be great if the stuff could work with basically any layout.

Another, maybe related, issue. I had to add an extra Controller class to my project since it’s running on 1.1.x.


class Controller extends CController {

    public $breadcrumbs = null;

    public $menu = null;

}

because Controller is used somewhere in auto-generated code.

IMHO it would also be OK to add these properties to CController, as it already has pageTitle and others.

And … please add a "download as .zip or .gz file" button.

I really do not want my app to have access to “its” own logic :o scary and separate downloading is also a pain.

So far from my side. Keep up the good work.

Best regards,

schmunk

[edit]

tested with rev. 2022

For some strange reason I can not login with a fresh webapp built from rev. 2022.

I always get the error:

Error 403

You are not allowed to access this page.

Even at http://localhost/webapp/index.php?r=gii/default/login as admin and as guest.

Anyone else got this problem?!

Thanks. I have fixed the success message bug.

We all know that no single code copy will fit for all needs and for all people.

Gii allows you to easily develop and use your own code templates for generating code.

For example, in your phundament project, you may create some code templates under your application’s folder so that the generated code can play well with your application.

We may consider supporting downloading the source files in a zip package, if more people are requesting for this feature.

Regarding 403 error, I guess it’s caused by mismatching of your IP address? The default security filter will only allow 127.0.0.1.

Yes, that’s it. Thanks.

On Mac OS X localhost defaults to the IPv6 address ::1.

While 127.0.0.1 works fine.

Hi Qiang,

any comments regarding the Controller stuff I mentioned.


class Controller extends CController {

    public $breadcrumbs = null;

    public $menu = null;

}

Should I open a ticket for this?

Best regards,

schmunk

I don’t think we should add breadcrumbs and menu to CController.

Unlike pageTitle, these two do not always exist in a controller.

As I said, you should consider creating your own version of code template if the default one doesn’t fit for your needs.

I will do so, for sure. <_<

I was just thinking about someone who has already an app running (like me), wants to create a new CRUD and then runs into this error.

And maybe he has already a class called controller … IMHO the generated CRUDs should not have any dependency by default.

Just my two cents.

Yeah, we did expect some upgrade pain due to the change of the code generators when we released 1.1.

We are facing a paradox, i.e., we either have to stick to the old behavior with less features, or we have to introduce some external dependency in order to implement some common features in the generated code.

The ultimate solution is gii which supports multiple sets of code template for different needs.

Don’t sacrifice features for backward-compatibility, the decision was fine.

I played around with gii a little bit more and now I got it :)

Applying the gii-style to phundament wasn’t a big deal. I’ve just renamed main.php to main2.php as a quick fix.

But the almost ultimate solution would be if the genereated code could be created with a theme.

As mentioned I added Controller.php to phundament to test the new CRUDs and gii, but I actually do not really use it elsewhere.

So I added there:


<?php


class Controller extends CController {

    public $breadcrumbs = null;

    public $menu = null;


    public function init(){

        Yii::app()->theme='yii-1.1';

    }

}

?>



And copied the needed files to this theme location.

Phundament comes with a component called EAutotheme which manages the inclusion of CSS and JS files.

btw: This was the first thing I wrote in yii, because I missed this feature from PRADO ;).

Anyway … I got one more glitch at the moment, and the reason it is not working is that I am unable to overwrite the layout in the theme. I placed it in the themes location, but the path is too specific I think, and beginContent() does not differentiate between layouts and views.


<?php $this->beginContent('application.views.layouts.main'); ?>

<div class="container">....</div>

<?php $this->endContent(); ?>

Maybe I’ve to dig into this a bit more … but if just the layout, CSS and JS files could be delivered within a theme, we could get a pretty clean solution here.

Maybe, a chooseable BaseController for the CRUDs would also help.

Best regards,

schmunk

Did you try clicking on those yellow highlighted fields in gii?

Ah, OK, I see, Thanks!

hehe … can we delete these two posts afterwards :rolleyes:

oh very nice :D only 1 issue I have where it creates the post vars with lowercase but the model classes with upercase… so by default it never saves anything :)

Also it seems to ignore the not null any fields for validation.

Could you explain in more details? "… it creates the post vars with lowercase but the model classes with upercase… so by default it never saves anything…"

My table names are in lowercase… but class name with uppercase (the model) When i create the CRUD it will create post / get vars in the controller like:

$model->attributes=$_POST[‘pages’];

instead of:

$model->attributes=$_POST[‘Pages’];

So it never saves anything and no error message.

Love the diff files btw… very usefull in early development when the data model is not fixed yet.

btw something different… with the svn version not sure other… the font for the captcha seems to be always be used by apache cannot delete it without stopping the apache service.

Also the ajax validation does not work anymore… as in 1.1.1 with CLI

Hi,

I tried set this up with two templates (gii’s default and phundament).

I stumbled upon this, GiiModule, line 213:




if(is_file("$path/$name/$className.php"))

{

	$generators[$name]=array(

		'class'=>"$alias.$name.$className",

	);

}



I put my templates in application.gii, and called the template folders ‘phundament’, but if I open the web-interface, the default ones are missing.

Looks like while scanning a new directory, the old values get erased, I fixed this by:




if(is_file("$path/$name/$className.php"))

{

	$generators[$name]['class'] = "$alias.$name.$className";

}

But … then you maybe get the problem that your GeneratorClass and template class do not match.

Is this expected? Because you can specify more than one generator path and multiple templates within a generator?!

Best regards,

schmunk

Extending gii comes in several ways. The most common way is to provide your own set of templates for the existing generators. Let’s assume you want to do this for the “crud” generator.

  1. Create a directory “protected/gii/crud/templates/compact”. The name “compact” refers to the name of the template set you want to create. If you don’t like the ‘default’ template at all and want to replace it with your own, you can name the new template set to be ‘default’.

  2. Copy all files from "framework/gii/generators/crud/templates" to this directory.

  3. Modify the copied files as you want. You may even delete some of them if they are not needed.

  4. Modify your app config and add “application.gii” to the ‘generatorPaths’ property of the gii module.

That’s all.

I think I did it exactly like this.

I also had it like that, btw: application.gii is the default and system.gii is always added to the scandirs first, right?

When I var_dump $generator in findGenerators() I see that first it’s filled with the templates from system.gii, and those are erased, when application.gii is scanned, even though the template has a different name.

I just expected it in a different way, would be cool to have the defaults available.

Another thing, could you update this in the gii module: column1.php and generator.php


<?php $this->beginContent('/layouts/main'); ?>

to:


<?php $this->beginContent('gii.views.layouts.main'); ?>

the latter one runs also when overwriting the layouts in a theme.

I did that, btw.

I created a yii-1.1 theme, available in my app skeleton, works like a charm, even with the gii module, but only when I overwrite the layout.