Yii Framework Forum: Giix Crud - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Giix Crud Rate Topic: *---- 1 Votes

#1 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 06 December 2012 - 12:10 PM

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

ARTICLES
article_id | title | description | author_id

AUTHORS
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

Thanks,

lilli
0

#2 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 06 December 2012 - 12:46 PM

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.
1

#3 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 06 December 2012 - 01:59 PM

View PostRodrigo Coelho, on 06 December 2012 - 12:46 PM, said:

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!

lilli
0

#4 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 06 December 2012 - 02:23 PM

View Postlilli, on 06 December 2012 - 01:59 PM, said:

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


Did you read the guide?

View Postlilli, on 06 December 2012 - 01:59 PM, said:

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


You can use CJuiDatePicker

View Postlilli, on 06 December 2012 - 01:59 PM, said:

- How can i generate automatically checkboxes and radio buttons?


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.

View Postlilli, on 06 December 2012 - 01:59 PM, said:

- 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?


giix won't create the logic for multiple insertions.
I recommend the multimodelform extension for this purpose.
1

#5 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 06 December 2012 - 02:47 PM

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?

thanks.
0

#6 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 06 December 2012 - 02:57 PM

View Postlilli, on 06 December 2012 - 02:47 PM, said:

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.


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!

View Postlilli, on 06 December 2012 - 02:47 PM, said:

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?


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.

View Postlilli, on 06 December 2012 - 02:47 PM, said:

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?


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.
1

#7 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 06 December 2012 - 03:29 PM

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.

bye.

lilli
0

#8 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 06 December 2012 - 03:57 PM

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

#9 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 09 December 2012 - 06:18 PM

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:

ARTICLES
article_id | title | description | author_id

AUTHORS
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?
0

#10 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 09 December 2012 - 06:51 PM

View Postlilli, on 09 December 2012 - 06:18 PM, said:

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!


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

View Postlilli, on 09 December 2012 - 06:18 PM, said:

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


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.
1

#11 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 09 December 2012 - 06:51 PM

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

#12 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 09 December 2012 - 07:37 PM

View PostRodrigo Coelho, on 09 December 2012 - 06:51 PM, said:

:)
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.


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

#13 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 09 December 2012 - 07:39 PM

View PostRodrigo Coelho, on 09 December 2012 - 06:51 PM, said:

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


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!
0

#14 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 09 December 2012 - 08:16 PM

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.
0

#15 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 13 December 2012 - 04:48 AM

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

<?php
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:
			array('allow', 
				'actions'=>array('admin','delete', 'assegna'),
				'users'=>array('admin'),
				),
...
...
...
	public function actionAssegna() {
		$model = new AssegnaCertificatiForm();
		$this->performAjaxValidation($model, 'assegnacertificatiform-form');

		if (isset($_POST['AssegnaCertificatiForm'])) {
			$model->setAttributes($_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'); ?>.
	</p>
        <?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 -->
<?php
echo GxHtml::submitButton(Yii::t('app', 'Save'));
$this->endWidget();
?>
</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?

thanks
0

#16 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 13 December 2012 - 05:14 AM

solved putting
if ($model->validate())
after //do something
0

#17 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 13 December 2012 - 10:04 AM

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

#18 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 13 December 2012 - 02:56 PM

View PostRodrigo Coelho, on 13 December 2012 - 10:04 AM, said:

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.

thanks.
0

#19 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 13 December 2012 - 04:54 PM

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

#20 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 06 January 2013 - 12:49 PM

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?


thanks!

lilli
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users