Yii Framework Forum: Giix — Gii Extended - Yii Framework Forum

Jump to content

  • (14 Pages)
  • +
  • « First
  • 4
  • 5
  • 6
  • 7
  • 8
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

Giix — Gii Extended a code generator for Yii PHP framework (scaffolding/code generation) Rate Topic: ***** 4 Votes

#101 User is online   Rodrigo Coelho 

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

Posted 08 July 2011 - 08:55 AM

Just override the method in your model (not in your base model).
0

#102 User is offline   enfield 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 288
  • Joined: 12-January 11

Posted 09 July 2011 - 06:26 PM

View Postmentel, on 08 July 2011 - 08:55 AM, said:

Just override the method in your model (not in your base model).


Can you please give me an example? I am not getting anywhere.

Here is my code that works with the representingColumn() as defined.
//model_1

//view
foreach($model->phones as $relatedModel) {
  echo GxHtml::valueEx($relatedModel);
}

//model
public function relations() {
  return array(
    'phones' => array(self::HAS_MANY, 'Phone', 'PartyId'), //model_2
}


//model_2

public static function representingColumn() {
  return 'PhoneNumber';
}


In my model1 view I want to diplay Name from model_2 though. Of course without changing the defined representingColumn() in model_2

I currently am not using giix to get the result through RAR, but would like to learn still.
foreach ($model->phones as $phone) {
  echo $phone->PhoneNumber;
}


BTW I started a new app with 1.9 and so far so good although I am only using the basic functionality to this point. I will upgrade another more complex app from 1.7 very soon.
0

#103 User is online   Rodrigo Coelho 

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

Posted 10 July 2011 - 07:04 AM

Sorry. I missed the "instead of changing the representingColumn".
The correct answer is: see the documentation for GxHtml::valueEx. There's a good explanation on the parameters there (and how it uses the representingColumn).

And thanks for your support!
0

#104 User is offline   Web Deli™ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-July 11
  • Location:Melbourne, Australia

Posted 22 July 2011 - 12:29 AM

View Postmentel, on 10 July 2011 - 07:04 AM, said:

see the documentation for GxHtml::valueEx


Which documentation? This:

 /**
         * Evaluates the value of the specified attribute for the given model.
         * This method is based on {@link CHtml::value}.
         * Changes: this method supports {@link GxActiveRecord::representingColumn()} and {@link GxActiveRecord::toString()}.
         * @see {@link CHtml::value} for more information.
         * @param mixed $model the model. This can be either an object or an array.
         * @param string $attribute the attribute name (use dot to concatenate multiple attributes).
         * Optional. If not specified, the {@link GxActiveRecord::__toString()} method will be used.
         * In this case, the fist parameter ($model) can not be an array, it must be an instance of GxActiveRecord.
         * @param mixed $defaultValue the default value to return when the attribute does not exist
         * @return mixed the attribute value
         */

Or are you referring to something else?

Can we have a URL?
0

#105 User is online   Rodrigo Coelho 

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

Posted 22 July 2011 - 01:09 AM

Yes, for now, that's the documentation.
And welcome to the forum!
0

#106 User is offline   Web Deli™ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-July 11
  • Location:Melbourne, Australia

Posted 22 July 2011 - 01:17 AM

Thanks for the welcome.

Are you able to point me in the right direction on the giix compatible way of pulling data from multiple models into the one view?

I have:

<?php $this->widget('zii.widgets.CDetailView', array(
	'data' => $model,
	'attributes' => array(
		array(
			'name' => 'personTitle',
			'type' => 'raw',
			'value' => $model->personTitle !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->personTitle)),
			array('PersonTitlecodes/view', 'id' => GxActiveRecord::extractPkValue($model->personTitle, true))):null,
			),
			'Person_FirstName',
			'Person_LastName',
			'Person_CourtesyName',
			'Person_DOB',
			array(
			'name' => 'personGender',
			'type' => 'raw',
			'value' => $model->personGender !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->personGender)),
			array('PersonGendercodes/view', 'id' => GxActiveRecord::extractPkValue($model->personGender, true))) : null,
			),
			'Person_Active:boolean',
			'Person_Deceased:boolean',
			'Person_UID',
			),
			));
?>


This encapsulates the details of of a primary model... I have another table with a bunch of "Person Details" that uses Person_UID as a FK.

I want to get the "../protected/views/Person/view.php" to contain BOTH base data & person details data.

Thanks for you advice in advance.
0

#107 User is offline   longterm 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 02-May 11

Posted 30 July 2011 - 11:40 AM

Hello everyone, I am new to working with giix but I am having troubles using saveMultiple and saveWithRelated.

Can someone please provide a basic example of using these?
0

#108 User is offline   Web Deli™ 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-July 11
  • Location:Melbourne, Australia

Posted 30 July 2011 - 11:12 PM

View PostWeb Deli™, on 22 July 2011 - 01:17 AM, said:

...
'Person_FirstName',
'Person_LastName',
'Person_CourtesyName',
'Person_DOB',
...
?>[/code]


Upon investigation - Gii, and by extension Giix - Is reading out the database table & column names in way which is impaired by the presence of Capitalization.

Therefore examples such as:

'Person_FirstName' must be: 'person_firstname'
'Person_LastName' must be: 'person_lastname'
'Person_CourtesyName' must be: 'person_courtesyname'
'Person_DOB' must be: 'person_dob'

Prior to Giix generating models.

While not the full solution, it is in at least in part one pre-requisite for success.

This lower case naming is also consistent with the Yii framework's own guidelines on coding conventions.
0

#109 User is offline   Dragos 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 01-August 11

Posted 01 August 2011 - 01:40 AM

Hi,

Start using giix recently(version 1.7) and I have a small problem with generating Many to many relations between classes. Is there a way to automatically generate this relations, or I have to edit the files to specify that a table in the database is a pivot?

For example I have 2 tables item and item_type with a many to many relation between them. I created another table itemxitemtype. Now, giix generates the following code for both model classes
'itemxitemtypes' => array(self::HAS_MANY, 'Itemxitemtype', 'ItemId'),


What should I do to have a valid many-to-many relation?

Thank you,
Dragos
0

#110 User is offline   enfield 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 288
  • Joined: 12-January 11

Posted 01 August 2011 - 03:30 PM

View PostDragos, on 01 August 2011 - 01:40 AM, said:

...Is there a way to automatically generate this relations, or I have to edit the files to specify that a table in the database is a pivot?
...


Dragos,
Not sure if I understand what you are asking because giix will automatically generate what you want. What version of giix are you using? And what db? (I have only used giix with MySQL)

In BaseItem you should see something like this if your db has the proper constaints...
'itemtypes' => array(self::MANY_MANY, 'ItemType', 'itemxitemtype(ItemId, ItemTypeId)'),

public function pivotModels() {
  return array(
    'itemtypes' => 'Itemxitemtype',
  );
}

0

#111 User is offline   longterm 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 02-May 11

Posted 01 August 2011 - 03:39 PM

View Postlongterm, on 30 July 2011 - 11:40 AM, said:

Hello everyone, I am new to working with giix but I am having troubles using saveMultiple and saveWithRelated.

Can someone please provide a basic example of using these?



Can anyone give me a simple example on how to use these. I have been over the code and comments many times but can not make sense on how to use these function. Please someone help.

I see in other extensions that the author provides an example of use which really helps. Giix seems to encapsulate many extensions into one. So although I can use other extensions to accomplish the same thing I would prefer to use something like giix instead.
0

#112 User is offline   dfu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 28-July 11
  • Location:Madrid, Spain

Posted 04 August 2011 - 05:14 AM

Great extension, thank you so much
0

#113 User is offline   Rait 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 15-August 11

Posted 15 August 2011 - 02:48 AM

I've ran into an issue trying to create relations with Giix.

This is what I have:

Tables in the DB
- processes(id,name,description) [list of available processes. Multiple processes are combined into stages. One process only belongs to one stage]
- stage_process_relations(process_id,stage_id) [which processes belong to which stage]
- stages(id,name,description) [list of available stages. One stage has multiple processes]
- tasks(id,name,process_id,description,start_time,end_time) [task items generated as needed. One task has one process.]

Using InnoDB as the engine and created the relations within the DB via PhpMyAdmin.

I created the models for processes and tasks using GiixModel Creator. Then added the following to the model - process.php
public function relations() {
		return array(
                    'tasks'=>array(self::HAS_MANY,'Task','process_id'),
                    'stages'=>array(self::HAS_ONE,'Stage','stage_process_relations(process_id,stage_id)'),
		);
	}


then ran the GiixCRUD Generator for Processes model. This created the following in _form.php
<div class="form">


<?php $form = $this->beginWidget('GxActiveForm', array(
	'id' => 'process-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 name">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model, 'name', array('maxlength' => 255)); ?>
		<?php echo $form->error($model,'name'); ?>
		</div><!-- row -->
		<div class="row description">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model, 'description'); ?>
		<?php echo $form->error($model,'description'); ?>
		</div><!-- row -->
		<div class="row cost_hour">
		<?php echo $form->labelEx($model,'cost_hour'); ?>
		<?php echo $form->textField($model, 'cost_hour', array('maxlength' => 10)); ?>
		<?php echo $form->error($model,'cost_hour'); ?>
		</div><!-- row -->
		<div class="row cost_each">
		<?php echo $form->labelEx($model,'cost_each'); ?>
		<?php echo $form->textField($model, 'cost_each', array('maxlength' => 10)); ?>
		<?php echo $form->error($model,'cost_each'); ?>
		</div><!-- row -->
		<div class="row productivity">
		<?php echo $form->labelEx($model,'productivity'); ?>
		<?php echo $form->textField($model, 'productivity', array('maxlength' => 20)); ?>
		<?php echo $form->error($model,'productivity'); ?>
		</div><!-- row -->

		<label><?php echo GxHtml::encode($model->getRelationLabel('tasks')); ?></label>
		<?php echo $form->checkBoxList($model, 'tasks', GxHtml::encodeEx(GxHtml::listDataEx(Task::model()->findAllAttributes(null, true)), false, true)); ?>
		<label><?php echo GxHtml::encode($model->getRelationLabel('stages')); ?></label>
		<?php echo $form->checkBoxList($model, 'stages', GxHtml::encodeEx(GxHtml::listDataEx(Stage::model()->findAllAttributes(null, true)), false, true)); ?>

<?php
echo GxHtml::submitButton(Yii::t('app', 'Save'));
$this->endWidget();
?>
</div><!-- form -->


and in ProcessController.php
<?php

class ProcessController extends GxController {

public function filters() {
	return array(
			'accessControl', 
			);
}

public function accessRules() {
	return array(
			array('allow',
				'actions'=>array('index','view'),
				'users'=>array('*'),
				),
			array('allow', 
				'actions'=>array('minicreate', 'create','update'),
				'users'=>array('@'),
				),
			array('allow', 
				'actions'=>array('admin','delete'),
				'users'=>array('admin'),
				),
			array('deny', 
				'users'=>array('*'),
				),
			);
}

	public function actionView($id) {
		$this->render('view', array(
			'model' => $this->loadModel($id, 'Process'),
		));
	}

	public function actionCreate() {
		$model = new Process;

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

		if (isset($_POST['Process'])) {
			$model->setAttributes($_POST['Process']);
			$relatedData = array(
				'stages' => $_POST['Process']['stages'] === '' ? null : $_POST['Process']['stages'],
				);

			if ($model->saveWithRelated($relatedData)) {
				if (Yii::app()->getRequest()->getIsAjaxRequest())
					Yii::app()->end();
				else
					$this->redirect(array('view', 'id' => $model->id));
			}
		}

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

	public function actionUpdate($id) {
		$model = $this->loadModel($id, 'Process');

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

		if (isset($_POST['Process'])) {
			$model->setAttributes($_POST['Process']);
			$relatedData = array(
				'stages' => $_POST['Process']['stages'] === '' ? null : $_POST['Process']['stages'],
				);

			if ($model->saveWithRelated($relatedData)) {
				$this->redirect(array('view', 'id' => $model->id));
			}
		}

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

	public function actionDelete($id) {
		if (Yii::app()->getRequest()->getIsPostRequest()) {
			$this->loadModel($id, 'Process')->delete();

			if (!Yii::app()->getRequest()->getIsAjaxRequest())
				$this->redirect(array('admin'));
		} else
			throw new CHttpException(400, Yii::t('app', 'Your request is invalid.'));
	}

	public function actionIndex() {
		$dataProvider = new CActiveDataProvider('Process');
		$this->render('index', array(
			'dataProvider' => $dataProvider,
		));
	}

	public function actionAdmin() {
		$model = new Process('search');
		$model->unsetAttributes();

		if (isset($_GET['Process']))
			$model->setAttributes($_GET['Process']);

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

}


everything seems correct to me, but when creating a new Process, this is what I get on submit:
Fatal error: Class name must be a valid object or a string in /data01/virt29637/domeenid/www.raitwebs.com/subs/yii/framework/db/ar/CActiveRecord.php on line 370


Any ideas what I'm doing wrong here? I have not yet begun to create any relations for the other tables, as I need to figure this out to begin with.
0

#114 User is online   Rodrigo Coelho 

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

Posted 15 August 2011 - 12:10 PM

View PostRait, on 15 August 2011 - 02:48 AM, said:

Any ideas what I'm doing wrong here?


No, I don't know, but I'm sure there are problems. giix should have generated the relations in the model.
Lets continue talking in Google Code, it is a better place for that. Please open a ticket there and I'll check giix.
0

#115 User is offline   jbatchelor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 22-August 11

Posted 01 September 2011 - 12:50 PM

I'm running into issues getting saveRelated to work.

The value for the column "id" is not supplied when querying the table "event_eventtypes". 


event_eventtypes is my pivot table.
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) NOT NULL DEFAULT '0',
  `eventtype_id` bigint(20) NOT NULL DEFAULT '0',
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,


EventsController
	public function actionUpdate($id) {
		$model = $this->loadModel($id, 'Events');


		if (isset($_POST['Events'])) {
			$model->setAttributes($_POST['Events']);
			$relatedData = array(
				'types' => $_POST['Events']['types'] === '' ? null : $_POST['Events']['types'],
				);

			if ($model->saveWithRelated($relatedData)) {
				$this->redirect(array('view', 'id' => $model->id));
			}
		}

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


BaseEvents
	public function relations() {
		return array(
			'eventEventtypes' => array(self::HAS_MANY, 'EventEventtypes', 'event_id'),
			'exhibition' => array(self::BELONGS_TO, 'Exhibitions', 'exhibition_id'),
			'institution' => array(self::BELONGS_TO, 'Institutions', 'institution_id'),
			
			'types' => array(self::MANY_MANY, 'Eventtypes', 'event_eventtypes(event_id,eventtype_id)'),
		);
	}

	public function pivotModels() {
		return array(
			'types' => 'EventEventtypes',
		);

0

#116 User is offline   jbatchelor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 22-August 11

Posted 01 September 2011 - 01:11 PM

View Postjbatchelor, on 01 September 2011 - 12:50 PM, said:

I'm running into issues getting saveRelated to work.

The value for the column "id" is not supplied when querying the table "event_eventtypes". 


event_eventtypes is my pivot table.
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `event_id` bigint(20) NOT NULL DEFAULT '0',
  `eventtype_id` bigint(20) NOT NULL DEFAULT '0',
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,


EventsController
	public function actionUpdate($id) {
		$model = $this->loadModel($id, 'Events');


		if (isset($_POST['Events'])) {
			$model->setAttributes($_POST['Events']);
			$relatedData = array(
				'types' => $_POST['Events']['types'] === '' ? null : $_POST['Events']['types'],
				);

			if ($model->saveWithRelated($relatedData)) {
				$this->redirect(array('view', 'id' => $model->id));
			}
		}

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


BaseEvents
	public function relations() {
		return array(
			'eventEventtypes' => array(self::HAS_MANY, 'EventEventtypes', 'event_id'),
			'exhibition' => array(self::BELONGS_TO, 'Exhibitions', 'exhibition_id'),
			'institution' => array(self::BELONGS_TO, 'Institutions', 'institution_id'),
			
			'types' => array(self::MANY_MANY, 'Eventtypes', 'event_eventtypes(event_id,eventtype_id)'),
		);
	}

	public function pivotModels() {
		return array(
			'types' => 'EventEventtypes',
		);




One issue I figured out is that having id columns in pivot tables is an issue. Now though when I hit save the page just refreshes.
0

#117 User is offline   jbatchelor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 22-August 11

Posted 02 September 2011 - 12:50 PM

View Postjbatchelor, on 01 September 2011 - 01:11 PM, said:

One issue I figured out is that having id columns in pivot tables is an issue. Now though when I hit save the page just refreshes.


For anyone who runs into issues in the future. You cannot have any other columns in your pivot table. So I had to remove the created_date and updated_date.
0

#118 User is online   Rodrigo Coelho 

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

Posted 02 September 2011 - 01:52 PM

Hi jbatchelor,

Please open a ticket if you can, with all the details you have, so I can work on this bug.
Please attach your relevant models and SQL scripts too.

Thanks!
0

#119 User is offline   ManInTheBox 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 75
  • Joined: 17-June 11

Posted 10 September 2011 - 05:50 PM

First of all, this is a great extension and I really like it!
Thank you mentel :)
Sorry if I repeat forum questions but I was wondering something:

1. Why is category (app) for
Yii::t('app', 'generatedLabel');
hardcoded?
I think that better solutions is to provide default category (eg app) and in model template generate just one sticky text field Category allowing users to enter their own category name.
2. Question about attributeLabels():
I was thinking about why some attributes (and relations) have null value like user_id, user(relation)... Any answer that I could say is to disable Yii to provide default label for attribute not listed in attributeLabels() like user_id => User ID. Am I wrong?
3. What the heck is 'minicreate' action listed in controller's rules() method? :)
Thanks in advance
0

#120 User is online   Rodrigo Coelho 

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

Posted 11 September 2011 - 06:14 AM

Hi ManInTheBox, thanks for your kind words.

View PostManInTheBox, on 10 September 2011 - 05:50 PM, said:

1. Why is category (app) for
Yii::t('app', 'generatedLabel');
hardcoded?
I think that better solutions is to provide default category (eg app) and in model template generate just one sticky text field Category allowing users to enter their own category name.


This can be an option later. Currently, giix is following what Gii does.

View PostManInTheBox, on 10 September 2011 - 05:50 PM, said:

2. Question about attributeLabels():
I was thinking about why some attributes (and relations) have null value like user_id, user(relation)... Any answer that I could say is to disable Yii to provide default label for attribute not listed in attributeLabels() like user_id => User ID. Am I wrong?


When the attribute is null, giix will take the name from the related model. It is used only for relations and for FK attributes.

View PostManInTheBox, on 10 September 2011 - 05:50 PM, said:

3. What the heck is 'minicreate' action listed in controller's rules() method? :)
Thanks in advance


That's something I have to clean. :)
0

Share this topic:


  • (14 Pages)
  • +
  • « First
  • 4
  • 5
  • 6
  • 7
  • 8
  • Last »
  • 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