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

Jump to content

  • (14 Pages)
  • +
  • « First
  • 6
  • 7
  • 8
  • 9
  • 10
  • 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

#141 User is offline   drumaddict 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 91
  • Joined: 04-October 10
  • Location:Athens,Greece

Posted 15 November 2011 - 01:49 AM

Hi mentel,thanks for your awesome extension!
I have set up a Category-Product MANY_MANY relation,and I am trying to call a CActiveDataProvider for the Product model filtered by a specific Category to which it belongs.(to use it in a ListView).There is no foreign key connecting the two models,only the pivot table,so I don't know what to use in CDbCriteria for the CActiveDataProvider argument.Thanks in advance !
0

#142 User is offline   Kyle Wallace 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 06-November 11

Posted 18 November 2011 - 05:49 AM

Hello everybody.

Things are going quite well with this extension however I have run into a minor issue that perhaps one of you smarter people might be able to help with.

Example:

TABLES
Tourist: ID, NAME
Place: ID, NAME
rel_tourist_visited: Tourist_ID, Place_ID
rel_tourist_wishlist: Tourist_ID, Place_ID


Pretty simple, in the example a TOURIST may have visited many PLACES and a PLACE may have had many TOURISTS who have visited.

And, a TOURIST may wish to visit many PLACES and the PLACE may have many TOURISTS who wish to visit.

Problem:

If there is only one many_many between TOURIST and PLACE things are fine, it works exceptionally however as I have two I have run into issues.

When you choose to add/edit a record it will show a many_many list of checkboxes, but only for ONE of the relationships (I think the second in the list, alphabetically).

Probably simple, but beyond me, any ideas? :)
0

#143 User is offline   Teatime 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 18-November 11

Posted 18 November 2011 - 07:31 AM

Hello,

When you have a many_many relation and you want to update with saveWithRelated, if update have to delete a line in your relation table, it can cause some issues :
$pivotModel = GxActiveRecord::model($pivotClassName)->findByPk($value);
=> wait for an int but with 2 FK in the relation table it gaves me an array :

A solution is to replace in line 481 of GxActiveRecord.php :

// Delete one active record at a time.
foreach ($deleteMap as $value) {
	$pivotModel = GxActiveRecord::model($pivotClassName)->findByPk($value);					
	if (!$pivotModel->delete()) {
		return false;
	}
}


By :
// Delete one active record at a time.
foreach ($deleteMap as $value) {
  if(is_array($value)){
    $pivotModel = GxActiveRecord::model($pivotClassName)->findByAttributes($value);				
  }else{
    $pivotModel = GxActiveRecord::model($pivotClassName)->findByPk($value);				
  }
  if (!$pivotModel->delete()) {
    return false;
  }
}


(Notice that in your controller you will have to set batch to false):
if ($model->saveWithRelated($relatedData, true, null, array('batch' => false))) {
  $this->redirect(array('view', 'id' => $model->id));
}


Thanks you for this nice extension :)
0

#144 User is offline   drumaddict 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 91
  • Joined: 04-October 10
  • Location:Athens,Greece

Posted 18 November 2011 - 08:31 AM

View Postdrumaddict, on 15 November 2011 - 01:49 AM, said:

Hi mentel,thanks for your awesome extension!
I have set up a Category-Product MANY_MANY relation,and I am trying to call a CActiveDataProvider for the Product model filtered by a specific Category to which it belongs.(to use it in a ListView).There is no foreign key connecting the two models,only the pivot table,so I don't know what to use in CDbCriteria for the CActiveDataProvider argument.Thanks in advance !


SOLVED


    $prod_criteria=new CDbCriteria;
        $prod_criteria->with=array('categories'=>array(
                                                                                                          'on'=>'categories.id=:cat_id' ,
   'together'=>true,
      'joinType'=>'INNER JOIN',
                                                                                                         	'params'=>array(':cat_id'=>$_GET['cat_id'])
                                                                                                            ));

        $prod_dataProvider=new CActiveDataProvider('Product', array(
                                                                                                                                    'criteria'=> $prod_criteria,
                                                                                                                                    'pagination'=>array(
                                                                                                                                                                         	'pageSize'=>2,
                                                                                                                                                                           	),

                                                                                                                                                  ));

0

#145 User is offline   Federico82 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 18-December 11

Posted 18 December 2011 - 01:14 PM

View PostKyle Wallace, on 18 November 2011 - 05:49 AM, said:

Hello everybody.

Things are going quite well with this extension however I have run into a minor issue that perhaps one of you smarter people might be able to help with.

Example:

TABLES
Tourist: ID, NAME
Place: ID, NAME
rel_tourist_visited: Tourist_ID, Place_ID
rel_tourist_wishlist: Tourist_ID, Place_ID


Pretty simple, in the example a TOURIST may have visited many PLACES and a PLACE may have had many TOURISTS who have visited.

And, a TOURIST may wish to visit many PLACES and the PLACE may have many TOURISTS who wish to visit.

Problem:

If there is only one many_many between TOURIST and PLACE things are fine, it works exceptionally however as I have two I have run into issues.

When you choose to add/edit a record it will show a many_many list of checkboxes, but only for ONE of the relationships (I think the second in the list, alphabetically).

Probably simple, but beyond me, any ideas? :)



Maybe this will help you...(sorry for my english)

My case TABLES:
person
organization
person_workfor_organization (relation)
person_memberof_organization (relation)

I can suggest that problem is about relation name generated in generateRelations() in ModelCode.php line 272 called
by "$this->relations = $this->generateRelations();" in GiixModelCode.php line 67 :

Inside generateRelations() is defined $relationName=$this->generateRelationName($table0, $table1, true); in ModelCode.php line 296

Well, creating "person" model with giix $relationName value for "person_workfor_organization" and "person_memberof_organization" tables was "organizations" so i've "lost" a relation caused by same array key assignment:
$relations[$className0][$relationName]="array(self::MANY_MANY, '$className1', '$unprefixedTableName($pks[0], $pks[1])')";

$relations['person']['organizations'] = "array(self::MANY_MANY, 'Organization', 'person_memberof_organization(id_person, id_organization_memberof)')"
$relations['person']['organizations'] = "array(self::MANY_MANY, 'Organization', 'person_worksfor_organization(id_person, id_organization_worksfor)')"

My solution?
simply replace "$relationName=$tableName;" instead of "$relationName=$this->generateRelationName($table[X], $table[X], true);" in ModelCode.php line 29x

0

#146 User is offline   xNicox 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 19-October 10

Posted 29 December 2011 - 10:50 AM

Hi, nice work !!
exactly what I need !

but ...
is there any way for this:

I have a table with fk , and i want to use the description of the related table eith this:

representingColumn


public static function representingColumn() {
return 'fk_grado_id'; //Ver esto !! tira la consulta SQL a la Base
}

like :
return 'fk_grado_id->descripcion'.

I try but I get an SQL error !!

Just tell me if you hava any better idea.

Best Regards
Lic. Nicolas Machado
0

#147 User is offline   bobosayhello 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 24-December 11

Posted 29 December 2011 - 09:04 PM

View Postmentel, on 08 November 2011 - 11:56 AM, said:


3: Yes. You are having problems because of an extra and unnecessary "id" field in the pivot table. Make the FK's the composite primary key.



I understand that a pivot table should only be used for maintaining a m2m relationship between two tables and there should not be any extra fields other than the the FK columns that compose the PK.

But sometimes, we really want to add some extra fields in the pivot table. Since it contains extra data, this makes it not only serve the purpose of a pivot table but also becomes a model itself. Then we may probably prefer to add an extra id column to use it as the PK instead. Can or will giix generate proper codes to handle this case in the future?

Currently, giix generates checkboxes in the view for a m2m relationship but if there is an extra column, for example a varchar(100) column, in the pivot table, giix can simply generate a text field beside the checkbox.

By the way, I really like your extension, it's very useful. B)
0

#148 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 05 January 2012 - 06:56 PM

Hi! I can't get this to work, which is awkward because it is only 3 steps and even I should be able to do that.

When I try use giix crud generator I get include(GxActiveRecord.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

I've tried having the files in both
protected/extentions/giix-crud
protected/extentions/

When trying to create a Model I get : Class 'GxActiveRecord' does not exist or has syntax error.

To me it seems like I have some kind of path issue.. But since I've tried all likely,unlikely places to put the files I have to ask here.
The settings in my main config file under import and gii is also correct.

When I read the readme under requirements it's not 100% clear what you mean so just be sure:
On my localhost I use wamp with latest mysql and apache.
0

#149 User is offline   Rodrigo Coelho 

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

Posted 05 January 2012 - 07:19 PM

View PostSampa, on 05 January 2012 - 06:56 PM, said:

When I read the readme under requirements it's not 100% clear what you mean so just be sure:
On my localhost I use wamp with latest mysql and apache.


I meant that it should work with your latest Apache and MySQL. But WAMP is not officially supported because I can't test it.

Check your PATH after including giix and after including some other file.
0

#150 User is offline   Fel 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 05-January 12

Posted 07 January 2012 - 12:27 AM

good
0

#151 User is offline   xNicox 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 19-October 10

Posted 11 January 2012 - 10:44 AM

hi, I added some lines of code to GxActiveRecord.
the idea is to parametrize representing Column separators.

when using something like:

	public static function representingColumn() {
		return array('apellido','nombre');
	}

the view shows LASTNAME-FIRSTNAME

so I created a function: in GxActiveRecord
	public static function representingColumnSeparator() {
		return '-';
	}

and then in your model ( not BaseXxx, in the real one ):
	public static function representingColumnSeparator() {
		return ', ';
	}


looks like: LASTNAME, FIRTSNAME

Regards.

This post has been edited by xNicox: 11 January 2012 - 10:45 AM

Lic. Nicolas Machado
0

#152 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 14 January 2012 - 01:36 PM

giix UNIQUE rule:

Hi, first of all, congrats for this excellent piece of code. I'm just starting with Yii and I found it very interesting.

Second, I found that giix does not create UNIQUE rule based on the UNIQUE flag of the field in the database. Is this an intended behaviour or is it a bug?

Again, thank you very much for this module!

Regards.
0

#153 User is offline   Rodrigo Coelho 

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

Posted 15 January 2012 - 08:32 AM

View Postjmariani, on 14 January 2012 - 01:36 PM, said:

Second, I found that giix does not create UNIQUE rule based on the UNIQUE flag of the field in the database. Is this an intended behaviour or is it a bug?


Hi jmariani,
Please try to generate with gii and check if it is ok.
giix uses gii to generate most of the code. If you don't see the 'unique' rule, please open a ticket so they can check it.

Before opening a ticket, please double-check your schema. I don't believe it's a bug in Yii.
1

#154 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 15 January 2012 - 02:51 PM

View Postmentel, on 15 January 2012 - 08:32 AM, said:

Hi jmariani,
Please try to generate with gii and check if it is ok.
giix uses gii to generate most of the code.

Before opening a ticket, please double-check your schema. I don't believe it's a bug in Yii.


Hi! Thank you for your prompt response!

You're right, Gii doesn't create UNIQUE rule also.

Here's my SQL (Produced by MySQL Workbench:

CREATE  TABLE IF NOT EXISTS `yiitest`.`MasterAccount` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `rfc` VARCHAR(13) NOT NULL ,
  `name` TEXT NOT NULL ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX `rfc_UNIQUE` (`rfc` ASC) )
ENGINE = InnoDB
AUTO_INCREMENT = 2
DEFAULT CHARACTER SET = utf8


Looks like Gii is not taking into account the UNIQUE INDEX directive.
0

#155 User is offline   Rodrigo Coelho 

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

Posted 16 January 2012 - 04:28 AM

jmariani, please read the Yii Conventions: database. Not following it may bite you later.

Also, it is important to read all the guide before working with Yii.
0

#156 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 20 January 2012 - 02:40 PM

View Postmentel, on 16 January 2012 - 04:28 AM, said:

jmariani, please read the Yii Conventions: database. Not following it may bite you later.

Also, it is important to read all the guide before working with Yii.


Thank you for your support.
Yii doesn't generate rules for UNIQUE indexes. Maybe on 2.0, Qiang said.

Regards
0

#157 User is offline   jmariani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 53
  • Joined: 12-January 12

Posted 20 January 2012 - 02:44 PM

I see that the admin view created by Gii has the advanced search form hidden by default, and Giix doesn't. Is it by design or is it a bug?

Eitherway, the fix is adding <div class="search-form" style="display:none"> on the search form when created.

[SOLVED] Also, I want to ask you if you can include a search form also in the index view or if you can give me or guide me to a way to add the search form into a index view.

Adeus!
1

#158 User is offline   Rodrigo Coelho 

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

Posted 20 January 2012 - 04:52 PM

View Postjmariani, on 20 January 2012 - 02:44 PM, said:

I see that the admin view created by Gii has the advanced search form hidden by default, and Giix doesn't. Is it by design or is it a bug?


It is by design. But planned to be changed in a coming version.
0

#159 User is offline   chumbx 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 26-January 12

Posted 26 January 2012 - 06:25 AM

Guys, how do I use GUID's there with that extension? Everytime I use a table with int's, it works.
For instance, i make the model and then the CRUD with a table(i.e User) with an ID type int, it works, i can go to my website/user and it works. If i use GUID instead of int into the field ID, it doesn't work.

Any help about the issue would be appreciated!
0

#160 User is offline   Rodrigo Coelho 

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

Posted 26 January 2012 - 07:49 AM

Hi chumbx,

Welcome to the forum.

Like I said in the issue you reported,

Your issue seems to be related to a route configuration.

Please check these links:
http://www.yiiframew...ontroller#route
http://www.yiiframew...1.1/CUrlManager

Also, don't forget to read the Yii guide before you start working with Yii:
http://www.yiiframew...c/guide/1.1/en/
0

Share this topic:


  • (14 Pages)
  • +
  • « First
  • 6
  • 7
  • 8
  • 9
  • 10
  • 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