Giiant - Gii On Steroids

Hi,

I just added the provider feature from gtc (Yii 1) to giiant.

[size="2"]

[/size]

[size="2"]Have a look at: [/size]https://github.com/s...k42/yii2-giiant

Best regards,

schmunk

[s]Unfortunately, I couldn’t try it out :(

Installing it with


php composer.phar require schmunk42/giiant @dev

gave an error:


requirements could not be resolved to an installable set of packages.

  Problem 1

    - The requested package schmunk42/giiant could not be found in any version, there may be a typo in the package name.



[/s]

Edit: Fixed it :)


php composer.phar require schmunk42/yii2-giiant @dev

instead of


php composer.phar require schmunk42/giiant @dev

Edit 2: No luck :(

You seem to have some conflicting ideas on namespacing :unsure:

I now get the following PHP error:


 PHP Fatal Error – yii\base\ErrorException	

Class 'schmunk42\giiant\Generator' not found

But trying to edit the configuration to use yii2-giiant also had no luck…

Thanks for your feedback, I fixed the README and updated master.

I was missing crud in the config here: [font="Consolas,"]schmunk42\giiant\crud\Generator[/font]

[font="Consolas,"]

[/font]

[font="Consolas,"]Please run [/font]

[font="Consolas,"]

[/font]

[font="Consolas,"]composer.phar update schmunk42/yii2-giiant[/font]

[font="Consolas,"]

[/font]

[font="Consolas,"]and let me know if it works now.[/font]

Yes. It works now :)

Looks very promising indeed. I’ll check out more next week, as I’m planning to maybe write some custom providers of my own.

Cool. For some inspiration about providers have a look at: https://github.com/schmunk42/gii-template-collection/tree/develop/fullCrud/providers

I am looking forward about any feedback. I thought i.e. about using an interface or traits for providers, but found no real advantage so far.

Here’s an example for a very app or project specific provider: https://gist.github.com/schmunk42/6641457

Hi Schmunk,

Unfortunately, I didn’t have the time to dig in custom providers, but I now have another problem:

Apparently there has been a change in the way objects are configured; after an Yii update, I suddenly get the error "Fatal error: Access to undeclared static property: Yii::$objectConfig" in my web.php config file.

It is caused by


\Yii::$objectConfig = [

	    // giiant provider configuration

	    'schmunk42\giiant\crud\providers\EditorProvider' => [

	        'columnNames' => ['description']

	    ]

	];

I searched the docs for how this configuration should look now, but couldn’t really find anything :(

This is due to a Yii 2 API change, see here for how to update the app config:

https://github.com/phundament/app/blob/4.0/app/config/web.php#L100

Corresponding guide section: http://stuff.cebe.cc/yii2docs/guide-configuration.html#setting-component-defaults-class-wide

Does Giiant have the same facilities Giix does for creating base models so if you ever need to change your DB schema you can just re-run Gii and it wont overwrite your code in the models?

I haven’t implemented this yet, but yes it’s planned.

Would be nice if you could create an issue for this: https://github.com/schmunk42/yii2-giiant/issues

We’d need a custom template and a generator for the model.

I’d suggest an additional attribute “createModel” which could be set to false (checkbox).

For the CRUDs I thought about a base class and almost empty controller classes, similar to this Yii 1 solution from Mike (https://github.com/mikehaertl/xcrudcontroller). [size=2]But this could also be handled with a custom template, so it’s optional - and also one additional attribute for the generator “createController”.[/size]

[size=2]

[/size]

btw: I am working on Gii from the command line: https://github.com/yiisoft/yii2/pull/2789 which also would fit nicely into your workflow, I guess.

Thanks a lot!

Also listed here now.

Sorry for bothering but I think I didn’t understand how to use providers

I’d like to have the Relation one applied to allow me to select value (dropdonw and not) coming for a related table.

HOw I do it?

[font="Arial"][size="2"]If you want to change the displayed value in the dropdown, you can add a getLabel() function to your model an regenerate the CRUDs. S[color="#151515"]ee [/color]https://github.com/s...erator.php#L143

We need to make this functionality more customizable, I think.

Another option would be to to create a custom provider for the related field, eg. to additionally set htmlOptions.

see https://github.com/s...allbackprovider

In your case, adjust the key (common\models\Foo.isAvailable) to match your model attribute, get the related data you want and replace checkbox with dropdown.

[color="#333333"]Does this help?[/color]

[color="#333333"]Do you use the giiant-batch command by the way?[/color][/size][/font]

Hi schmunk,

I am getting mad ad I am not sure if it si because I’m not getting the real differences between YII 1.1 and YII 2.0 or because I converted myself into a dumb!!!

Anyway, I am not using the batch for the moment, I am still trying to evaluate which “advanced GII” I’d like to use as my toolset.

I am used to YII 1.1.16 and Awecrud with some changes I made to have it just as I like it and one of the things "included" were the realtion things out of the box.

So my main job had to be done at DB level and as a conseuquence to the model level where eventually i could change something to make it more compliant.

SO if I were defining that the representing column of a realted table was for istance a date instead of a description i could get that data automatically into any related table reference (description into the grid, dropdowns in a form etc).

Am I starting from the right place if I’d like to have the same using your extension?

Again thank you in advance for any light you can shed on this!

Kavi

Hi again,

I think I need to clarify my previous comment and also my expectations so, maybe, my asking would appear clearer…

Since the idea behind giiant is to "restore" some of the good things coming from giix and awecrud, I was expecting to see mostly the same things in a more elegant YII2 styled script.

And I can see this in the way you Schmunk did it, no doubt but…

… I am missing some features that hopefully are already in but I am not able to grasp (not sure if it is due to YII2 changes or because I dont understand them)!

An admin.php (now index.php) out of the box with "awecrud":




<?php 

	$this->widget('bootstrap.widgets.TbExtendedGridView',

		array(

			//'fixedHeader' => true,

			//'headerOffset' => 40,

			'responsiveTable' => true,

			'template' => "{pager}\n{summary}\n{items}\n{pager}",

			'id' => 'one-subsidiary-user-grid',

			'type' => 'striped bordered condensed',

			'dataProvider' => $model->search(),

			'filter' => $model,

			'columns' => array(

				array(

                    'name' => 'subsidiary_id',

                    'value' => 'isset($data->subsidiary) ? $data->subsidiary : null',

                    'filter' => CHtml::listData(OneSubsidiary::model()->findAll(), 'id', OneSubsidiary::representingColumn()),

                ),

				array(

                    'name' => 'user_id',

                    'value' => 'isset($data->user) ? $data->user : null',

                    'filter' => CHtml::listData(ModUser::model()->findAll(), 'id', ModUser::representingColumn()),

                ),

				array(

					'name' => 'is_default',

					'value' => '($data->is_default == 0) ? Yii::t(\'AweCrud.app\', \'No\') : Yii::t(\'AweCrud.app\', \'Yes\')',

					'filter' => array('0' => Yii::t('AweCrud.app', 'No'), '1' => Yii::t('AweCrud.app', 'Yes')),

					),

				array(

					'class'=>'bootstrap.widgets.TbButtonColumn',

					'header' => Yii::t('AweCrud.app', 'Operations'),

				),

			),

		)

	); 

?>



A _form.php out of the box with "awecrud":




<div class="form">

	<?php

		/** @var OneSubsidiaryUserController $this */

		/** @var OneSubsidiaryUser $model */

		/** @var AweActiveForm $form */

		$form = $this->beginWidget('ext.AweCrud.components.AweActiveForm', array(

			'id' => 'one-subsidiary-user-form',

			'enableAjaxValidation' => true,

			'enableClientValidation'=> true,

		)); 

	?>


	<p class="note">

		<?php echo Yii::t('AweCrud.app', 'Fields with') ?> <span class="required">*</span>

		<?php echo Yii::t('AweCrud.app', 'are required') ?>.

	</p>


	<?php echo $form->errorSummary($model) ?>


	<?php echo $form->dropDownListRow($model, 'subsidiary_id', array(''=>Yii::t('app','ddSelect')) + CHtml::listData(OneSubsidiary::model()->findAll(), 'id', OneSubsidiary::representingColumn())) ?>

	<?php echo $form->dropDownListRow($model, 'user_id', array(''=>Yii::t('app','ddSelect')) + CHtml::listData(ModUser::model()->findAll(), 'id', ModUser::representingColumn())) ?>

	<?php echo $form->checkBoxRow($model, 'is_default') ?>


	<div class="form-actions">

		<?php $this->widget('bootstrap.widgets.TbButton', array(

			'buttonType'=>'submit',

			'type'=>'primary',

			'label'=>$model->isNewRecord ? Yii::t('AweCrud.app', 'Create') : Yii::t('AweCrud.app', 'Save'),

		)); ?>

		<?php $this->widget('bootstrap.widgets.TbButton', array(

			'label'=> Yii::t('AweCrud.app', 'Cancel'),

			'htmlOptions' => array('onclick' => 'javascript:history.go(-1)')

		)); ?>

	</div>


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

</div>



The main issue solved by the “awecrud” extension in YII 1.1 was [size=“2”]getting the related table data right associated to the column of the model whose “index view” was built on and generate the dropdowns for the table’s foreign keys like I am putting in evidence extracting them form the above code:[/size]




array(

	'name' => 'subsidiary_id',

	'value' => 'isset($data->subsidiary) ? $data->subsidiary : null',

	'filter' => CHtml::listData(OneSubsidiary::model()->findAll(), 'id', OneSubsidiary::representingColumn()),

),



and




<?php echo $form->dropDownListRow($model, 'subsidiary_id', array(''=>Yii::t('app','ddSelect')) + CHtml::listData(OneSubsidiary::model()->findAll(), 'id', OneSubsidiary::representingColumn())) ?>



Can I get something like this "out of the box" with GIIANT? If yes can you help me in doing it?

Again thank you in advance for any light you can shed on this.

Regards

Kavi

Am I right in thinking this is included in the package here: http://phundament.com/

@dustbin1_uk Yes, giiant is included in Phundament. We’re doing some final restructuring at the moment to get ready for 4.0.0-rc1

@Kavitama it’s not as out of the box as it was in Yii1 with gtc or awecrud …

The basic idea would be either to define a callback in the universal CallbackProvider or to add this to the Relation provider.

This is an example for a column with a filter (dropdown) for a related [size=2]"Gallery"[/size][size=2] [/size][size=2]model.[/size]




    $columnAtttributes = [

        'app\models\Gallery'             => '[

            "class" => yii\\grid\\DataColumn::className(),

            "attribute" => "gallery_id",

            "value" => function($model){

                $rel = $model->getGallery()->one();

                return yii\helpers\Html::a($rel->title,["/crud/gallery/view","id" => $rel->id]);

            },

            "format" => "raw",

            "filter" => yii\helpers\ArrayHelper::map(

                app\models\Gallery::find()->all(),\'id\',\'title\'

            )

        ]',

See here for the usage: [size=2]https://github.com/schmunk42/yii2-giiant#universal-callbackprovider[/size]

[size=2]

[/size]

[size=2]I still need to find a way to add this feature in a safe way by default.[/size]

Fair enough!

I will dive into the callbackprovider and have enough time to wait for a "safe schmunk solution" :slight_smile:

Is it correct if I say the new structure in YII2 is complicating this way of delivering applications??

> [color=#1C2837][size=2]Is it correct if I say the new structure in YII2 is complicating this way of delivering applications?? [/size][/color]

[color=#1C2837][size=2]

[/size][/color]

[color=#1C2837][size=2]Depends on your app structure :)[/size][/color]

[color=#1C2837][size=2]We developed Phundament as an application template with focus on Docker from development to deployment.[/size][/color]

[color=#1C2837][size=2]With this, our deployments are running very smooth now, we’re working on 4.0.0-RC1 of Phundament btw.[/size][/color]

I have been looking at Phundament lately and I like the idea behind that but I really need to solve that "piece of cake" I was showing.

My developments are mainly based on complex DB structures in which I find myself very attuned and then generate the app, that is why I was so unhappy to see those YII2 changes in the structure of doing things.

I have the doubt this is affecting a lot the way YII2 is really competing with other frameworks but this is off topic and only my personal opinion!