Giix Crud

Hi everyone,

I’m using GIIX for CRUD operations on tables.

is not well documented so I have a lot of doubts.

i’m using an example to explain my problem:

we have these tables


article_id | title | description | author_id


author_id | name | etc…

How can I use GIIX, automatically, to generate a CRUD for the ARTICLES table that for insertion and search operations, instead of using a text input for author_id, give me a dropdown list with the names of authors?

Sorry for my English



Hi lilli,

Thanks for using giix.

giix will create the dropdown list automatically when you setup a FK constraint (using InnoDB if your using MySQL) for the field author_id in the table ARTICLES.

That’s great!!!!!!!! Thank you!!!!!! :lol:

Could you answer to some other questions, please?

I don’t want to bother you but i can’t find any documentation or examples on the web.

  • What if i have a timestamp field and i would like to have the jquery datapicker for insertion?

  • How can i generate automatically checkboxes and radio buttons?

  • Suppose that i have a table USERS and each user can have n emails. Is it possible to generate a multiple email insertion (and visualization) with GIIX?

Thanks a lot!


Did you read the guide?

You can use CJuiDatePicker

giix will generate them for your relations. Everything else you have to do by hand.

Also, please note that the generated code usually has to be updated according to your app requirements.

giix won’t create the logic for multiple insertions.

I recommend the multimodelform extension for this purpose.

I’m quite new to yii (i’ve just developed another webapp), but i read the guide, but it’s the first time for me to use giix.

Anyway, thanks for your answers. Very useful.

Two other questions and then i’ll stop. i promise. :-X

  1. How to handle HAS_MANY and MANY_MANY relations with giix? just setting FK’s in the db?

  2. the classical ajax "select state => then select region of the selected state => then select city of the selected region" is it possible with giix or i have to do it by hand?


I’m glad to know you did. It is an important step in learning the framework.

I didn’t want to be rude, I’m sorry if I left this impression.

I’m happy to help!

No problem. You can keep asking as much as you like.

Yes. You have to setup the FK constraints (remember to use InnoDB if you’re using MySQL) and giix will handle the relations automatically.

It isn’t giix’s purpose to offer this feature.

But you can search on this website, there are lots of examples (and maybe extensions) for dealing with this.

Pleas ask again if you need further clarification.

thanks rodrigo! don’t worry. i can’t think bad of someone who developed an extension for helping a community, like you did. ::)

as concern the last point i don’t want you to misunderstood. i don’t mean a feature for the cities, it was just an example for ajax selects.

anyway. thanks a lot.



No problem. So answering correctly your last question: yes, it is possible with giix. I have no examples, though.

hi rodrigo! i’m still here… :P

i’ve start using your extension and… it’s great! saving time has never been so easy. thank you!

but i have another question:

let’s take the example i’ve already made:


article_id | title | description | author_id


author_id | name | etc…

so there is a foreing key ‘author id’ in table ARTICLES

through giix in Articles controller there will be this relation:

‘authors’ => array(self::BELONGS_TO, ‘Authors’, ‘author_id’),

and in Authors:

‘articles’ => array(self::HAS_MANY, ‘Articles’, ‘author_id’),

my question is:

why in the create view for the Authors insertion, there are checkboxes with all the Articles to choose from?


Thanks for the compliment! You can leave your vote on the extension page (the thumb icon).

That’s because giix doesn’t know the specific requirements of your app.

This could apply for other app or for other relation, but is not the best strategy for this specific form.

After the code is generated, you will have to make changes to adapt it to your specific requirements. In this case, you will simply remove the checkboxes.

And a pro tip: you will avoid headaches by following these conventions.

voted! you deserve a donation also. let me finish this work so i’ll get some money.

Yeah sure. i’m trying to follow them (everything but i really can’t use tbl_ prefix). the example (articles and authors) is not what i’m really doing, so i’ve just wrote them in uppercase to make them more visible.

thanks for the advices!

Wow, that’s extraordinary! Thank you very much :)

I don’t use table prefixes, too. Don’t worry about them.

Good to know you’re following the conventions already.

Please post again in case you need more info.

hi rodrigo… :rolleyes: did you think i stopped annoying you? wrong! :P

well, that’s my new problem:

i need to validate a form with fields that are not related to a table so i made this class


class AssegnaCertificatiForm extends CFormModel


	public $n_certificati;


	public function attributeLabels() {

		return array(

				'n_certificati' => Yii::t('app', 'N certificati da assegnare'),



	public function rules() {

		return array(

				array('n_certificati', 'required'),

				array('n_certificati', 'numerical', 'integerOnly'=>true),			




this controller:


				'actions'=>array('admin','delete', 'assegna'),






	public function actionAssegna() {

		$model = new AssegnaCertificatiForm();

		$this->performAjaxValidation($model, 'assegnacertificatiform-form');

		if (isset($_POST['AssegnaCertificatiForm'])) {


			//do something



		$this->render('assegna', array( 'model' => $model));


and this view

<div class="form">

<?php $form = $this->beginWidget('GXActiveForm', array(

	'id' => 'assegnacertificatiform-form',

	'enableAjaxValidation' => true,




	<p class="note">

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


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

	<div class="row">

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

	<?php echo $form->textField($model, 'n_certificati'); ?>

	<?php echo $form->error($model,'n_certificati'); ?>

	</div><!-- row -->


echo GxHtml::submitButton(Yii::t('app', 'Save'));



</div><!-- form -->		

the validation is working (on lostfocus) but not the performAjaxValidation as on the other create actions of other controllers (if the field is empty it does not Yii::app()->end() ).

could you tell me why?


solved putting

if ($model->validate())

after //do something

Please also notice that the correct name of the class is GxActiveForm instead of GXActiveForm.

you don’t miss a thing! what a guru. ;)

yes i noticed it because in local it’s not case sensitive but on the remote server it is, and i realized just in that moment.


That’s why I recommend using Linux on dev, also :)

hi rodrigo.

long time has passed. :lol:

i have a new question for you: what about the image (or any other file) upload in giix?

is it implemented or, in the case it is not, which extension do you use?