giix — gii Extended a code generator for Yii PHP framework (scaffolding/code generation)
#101
Posted 08 July 2011 - 08:55 AM
Check my extension
giix: a code generator for Yii.

The complete beginner's study guide for the Yii Framework
#102
Posted 09 July 2011 - 06:26 PM
mentel, on 08 July 2011 - 08:55 AM, said:
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.
#103
Posted 10 July 2011 - 07:04 AM
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!
Check my extension
giix: a code generator for Yii.

The complete beginner's study guide for the Yii Framework
#104
Posted 22 July 2011 - 12:29 AM
mentel, on 10 July 2011 - 07:04 AM, said:
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?
#105
Posted 22 July 2011 - 01:09 AM
And welcome to the forum!
Check my extension
giix: a code generator for Yii.

The complete beginner's study guide for the Yii Framework
#106
Posted 22 July 2011 - 01:17 AM
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.
#107
Posted 30 July 2011 - 11:40 AM
Can someone please provide a basic example of using these?
#108
Posted 30 July 2011 - 11:12 PM
Web 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.
#109
Posted 01 August 2011 - 01:40 AM
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
#110
Posted 01 August 2011 - 03:30 PM
Dragos, on 01 August 2011 - 01:40 AM, said:
...
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',
);
}
#111
Posted 01 August 2011 - 03:39 PM
longterm, on 30 July 2011 - 11:40 AM, said:
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.
#113
Posted 15 August 2011 - 02:48 AM
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.
#114
Posted 15 August 2011 - 12:10 PM
Rait, on 15 August 2011 - 02:48 AM, said:
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.
Check my extension
giix: a code generator for Yii.

The complete beginner's study guide for the Yii Framework
#115
Posted 01 September 2011 - 12:50 PM
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',
);
#116
Posted 01 September 2011 - 01:11 PM
jbatchelor, on 01 September 2011 - 12:50 PM, said:
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.
#117
Posted 02 September 2011 - 12:50 PM
jbatchelor, on 01 September 2011 - 01:11 PM, said:
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.
#118
Posted 02 September 2011 - 01:52 PM
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!
Check my extension
giix: a code generator for Yii.

The complete beginner's study guide for the Yii Framework
#119
Posted 10 September 2011 - 05:50 PM
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
#120
Posted 11 September 2011 - 06:14 AM
ManInTheBox, on 10 September 2011 - 05:50 PM, said:
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.
ManInTheBox, on 10 September 2011 - 05:50 PM, said:
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.
ManInTheBox, on 10 September 2011 - 05:50 PM, said:
Thanks in advance
That's something I have to clean.
Check my extension
giix: a code generator for Yii.

The complete beginner's study guide for the Yii Framework

Help















