Giix — Gii Extended

Hi Rodrigo,

Just trying out Giix. So far i’ve just created all my models and CRUD.

Iit’s been great for relational data. I have a small problem. In a my item view it links who created the item. But when I click on the link I get “include(item01.lister.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory”




'value' => $model->lister !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->lister)), array('item01.lister/view', 'id' => GxActiveRecord::extractPkValue($model->lister, true))) : null,



All the other FK links work fine though. What may I have done wrong? The Model and Controller both exist. I’ve even deleted them and regenerated them. All other models/controllers seem to be working fine.

Thanks

Jonny

EDIT: I wanted to really text Giix so I loaded a larger more comprehensive DB and went through and this problem didn’t seem to happen. Not sure why, but it kind of resolved itself - Thanks

More than one representingColumn.

Hello,

When I have more than one representing column, like:


	public static function representingColumn() {

		return array('country','prefix');

	}



Is there some better way to get the value for only one of the representing columns than to get all and then split like


explode('-',$string_representingColumn);

Hi

I have this new thread in the general framework questions as I’m not sure if it is necessarily a Giix problem. Could somebody let me know if this thread seems to be a Yii (In general) issue or Giix please.

Cdbexception Error Using Giix Generators

I can confirm that this seems to be a problem in Giix as i’ve redone everything with standard Gii and I can access the create/update/admin portions of every model, including the one that was producing the cdbException() error.

Good to know, sorry for the delay.

Hi TonyBoy,

Please take a look at GxActiveRecord::__toString. It uses the value of the representing columns to build a string representation of your model instance. You can override this method to change the representation.

If you just want to change the separator, use GxActiveRecord::repColumnsSeparator.

I’ll take a look there.

I have installed GIIX extension. I try to execute it with the following url/app/index.php/giix but it did not work?

any idea to run it plz?

Hi,

Thanks for your great extension and hard work. I was wondering if this extension is still being actively developed and if so if there is a roadmap for it? What are the plans/future for this extension? Will this continue to be enhanced and updated? Is there a chance that this extension (or something like gii-template-collection) will be a standard part of YII?

best regards, Gos

Please refer to the readme and install files, you’ll get the info you need there.

It is important to understand how the framework works and how to use Gii. I recommend that you read the guide, too.

Hi Gos,

This extension is supported by me and by its users. You can ask questions here.

There is a private roadmap, but the development is currently suspended due to lack of time.

My plans for the future include a complete rewrite to launch giix 2 for Yii 2.0.

I don’t know whether the core framework developers plan to integrate the features from giix or similar extensions into Gii. You should ask them instead.

Hi!

Just a question : can I use saveWithRelated for a MANY_MANY relation with data. For instance :




Person(int id)-Seen(int id_person,int id_movie,date date,bool liked)-Movie(int id)

Can I use saveWithRelated to save one person with all the movies he has seen and the relation data (date and liked wich cannot be null)?

If not, how to do it nicely?

Cheers!

saveWithRelated will save only the FKs.

You will probably have to save the models manually.

Hi, I’m a Yii beginner.

I generated Giix CRUD on a Giix-generated model that had a relation to another model, namely the model from this extension: imagegallerymanager - "Gallery".

The Gallery model just extends CActiveRecord, so this piece of code fails:


<?php echo $form->labelEx($model,'gallery_id'); ?>

with "Gallery and its behaviors do not have a method or closure named "label".".

If I add the label static function in from GxActiveRecord, or even make the Gallery class extend GxActiveRecord, it just generates more errors, like complaining about findAllAttributes missing and a bad SQL string.

My question is: do all models in the application that have relations need to be GxActiveRecord, or can they mix and match? How would I make a Giix model work with a relation to this 3rd party extension model?

pineappleclock, you can replace the "null" value for the keys "gallery_id" and "gallery" on getAttributeLabels on your model with a string. That will fix the error.

Hi,

Gixx offers a separated model and basemodel. Would it be possible to do the same for controllers?

Thanks! Sacha

Models are separated so that you can re-generate the basemodel often after you change your database schema.

The generated controller has just minimal, example code. Most of it will be rewritten by you.

But all controllers generated by giix will extend a common class Controller.

If you still need separated controllers, you can modify the template giix uses to generate your code.

Hi!

I have a table with company’s data and another table with the contact’s data. So, I decided to use this great extension to generate my CRUD, but when I try to update some company with contacts I receive this error message: “Object of class Contato could not be converted to int” and this doesnt happen when the company doesnt have contacts.

Is this a bug or some incompatibility with yiistrap extension?

This is the stack trace:

PHP notice

 		Object of class Contato could not be converted to int	





   		/opt/lampp/htdocs/polyafer-app2/protected/extensions/bootstrap/helpers/TbHtml.php(987)

975     	$checkAllLast = TbArray::popValue('checkAllLast', $htmlOptions);

976     	if ($checkAll !== null) {

977         	$checkAllLabel = $checkAll;

978         	$checkAllLast = $checkAllLast !== null;

979     	}

980 

981     	$items = array();

982     	$baseID = $containerOptions['id'] = TbArray::popValue('baseID', $htmlOptions, parent::getIdByName($name));

983     	$id = 0;

984     	$checkAll = true;

985 

986     	foreach ($data as $value => $label) {

987         	$checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select);

988         	$checkAll = $checkAll && $checked;

989         	$htmlOptions['value'] = $value;

990         	$htmlOptions['id'] = $baseID . '_' . $id++;

991         	if ($inline) {

992             	$htmlOptions['label'] = $label;

993             	self::addCssClass('inline', $labelOptions);

994             	$htmlOptions['labelOptions'] = $labelOptions;

995             	$items[] = self::checkBox($name, $checked, $htmlOptions);

996         	} else {

997             	self::addCssClass('checkbox', $labelOptions);

998             	$option = self::checkBox($name, $checked, $htmlOptions);

999             	$items[] = self::label($option . ' ' . $label, false, $labelOptions);

– /opt/lampp/htdocs/polyafer-app2/protected/extensions/bootstrap/helpers/TbHtml.php(1719): TbHtml::checkBoxList("Empresa[contatos]", array(Contato, Contato), array(1 => "Ednei Rodrigues", 2 => "Matheus Benaia"), array("id" => "Empresa_contatos"))


1714     	}

1715     	$name = TbArray::popValue('name', $htmlOptions);

1716     	$unCheck = TbArray::popValue('uncheckValue', $htmlOptions, '');

1717     	$hiddenOptions = isset($htmlOptions['id']) ? array('id' => parent::ID_PREFIX . $htmlOptions['id']) : array('id' => false);

1718     	$hidden = $unCheck !== null ? parent::hiddenField($name, $unCheck, $hiddenOptions) : '';

1719     	return $hidden . self::checkBoxList($name, $selection, $data, $htmlOptions);

1720 	}

1721 

1722 	/**

1723  	* Generates an inline check box list for a model attribute.

1724  	* @param CModel $model the data model.

									/opt/lampp/htdocs/polyafer-app2/protected/extensions/bootstrap/widgets/TbActiveForm.php(379): [b]TbHtml[/b]::[b]activeCheckBoxList[/b](Empresa, &quot;contatos&quot;, array(1 =&gt; &quot;Ednei Rodrigues&quot;, 2 =&gt; &quot;Matheus Benaia&quot;), array())				

374  	* @return string the generated checkbox list.

375  	* @see TbHtml::activeCheckBoxList

376  	*/

377 	public function checkBoxList($model, $attribute, $data, $htmlOptions = array())

378 	{

379     	return TbHtml::activeCheckBoxList($model, $attribute, $data, $htmlOptions);

380 	}

381 

382 	/**

383  	* Renders an inline checkbox list for a model attribute.

384  	* @param CModel $model the data model.



– /opt/lampp/htdocs/polyafer-app2/protected/views/empresa/_form.php(79): TbActiveForm->checkBoxList(Empresa, "contatos", array(1 => "Ednei Rodrigues", 2 => "Matheus Benaia"))


74             	TbHtml::submitButton(Yii::t('app','Save'), array('color' => TbHtml::BUTTON_COLOR_PRIMARY)),

75             	TbHtml::resetButton(Yii::t('app', 'Reset')),

76     	)); ?>

77     	

78             	<label><?php echo GxHtml::encode($model->getRelationLabel('contatos')); ?></label>

79     	<?php echo $form->checkBoxList($model, 'contatos', GxHtml::encodeEx(GxHtml::listDataEx(Contato::model()->findAllAttributes(null, true)), false, true)); ?>

80     	<label><?php echo GxHtml::encode($model->getRelationLabel('enderecos')); ?></label>

81     	<?php echo $form->checkBoxList($model, 'enderecos', GxHtml::encodeEx(GxHtml::listDataEx(Endereco::model()->findAllAttributes(null, true)), false, true)); ?>

82     	<label><?php echo GxHtml::encode($model->getRelationLabel('orcamentoServicos')); ?></label>

83     	<?php echo $form->checkBoxList($model, 'orcamentoServicos', GxHtml::encodeEx(GxHtml::listDataEx(OrcamentoServico::model()->findAllAttributes(null, true)), false, true)); ?>

84     	<label><?php echo GxHtml::encode($model->getRelationLabel('orcamentoVendas')); ?></label>

Hi

I was recognizing that the giix generated base models where missing the label in representing columns. The related label was null.

I had the following constellation:

  • Labels in the base model where generated with [font="Courier New"]Yii::t()[/font];

  • All attributes in the table where in lowercase e.g.[font="Courier New"] tablename.myattribute[/font]

  • The generated attributes in the model e.g. [font="Courier New"]Myattribute[/font]

  • Foreignkey attributes in this form: [font="Courier New"]tablename.myattribute_id[/font]

  • The generated attributes in the model e.g. [font="Courier New"]null[/font]

So how to get a correct label for the foreign-key columns in a table without changing the code of giix?

My solution is the following:

Copy the folder recursively from default to your foldername:


protected\extensions\giix\generators\giixModel\templates\default\

e.g.


protected\extensions\giix\generators\giixModel\templates\mytemplates\

So you can select mytemplates before generating the models.

Edit


protected\extensions\giix\generators\giixModel\templates\mytemplates\_base\basemodel.php

At public function attributeLabels()

Comment out or delete


<?php echo "'{$name}' => null,\n"; ?>

into


<?php //echo "'{$name}' => null,\n"; ?>

and therefore add the following code:


 <?php

        $labelRelated=$name;

        $labelRelated = str_replace('_id','',$labelRelated);

        $labelRelated = ucwords(strtolower($labelRelated));

        echo "'{$name}' => Yii::t('app','{$labelRelated}'),\n"; 

 ?>

And regenerate the basemodels with GiixModel Generator!

Maybe this is not a consistent solution to add to future versions of giix but at least it works and would not be overwritten from future updates.

Thats it.

B)

Keywords: attributeLabels, getRelationLabel, getAttributeLabel

i used giix a few days ago, everything is ok but the accessrules not have place, i cant make start to generate privacity in some page, somebody know if i can implement this metod in giix and how?(excuse for my english not is my mother language)

The empty parameter in the following line of code is ignored. I would like for this dropdown list to allow an empty value. The value is used to create a row in an association table, but creating a row is not always required.

<pre>

<?php echo $form->dropDownList($model, ‘leads’, GxHtml::encodeEx(GxHtml::listDataEx(Lead::model()->findAllAttributes(null, true)),array(‘empty’=>’-- Select Leads --’), true)); ?>

</pre>