Yii Framework Forum: EXTENDING CRUD GENERATION (scaffolding) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

EXTENDING CRUD GENERATION (scaffolding) Rate Topic: -----

#1 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 03 January 2010 - 08:04 PM

HI,

I am return after same pause!

Anyone has extended the Yii Crud default system for same aditional features?

Like search, limit browsing fields (under admin manage),lookup between two or more tables from FK fiels...

if have not, Anyone can work with me to develop this feature for YII?

Regards!!!
trying build code for Generate complete CRUD source code with YII... any help?
post comments here:
EXTENDING CRUD GENERATION (scaffolding)

old tentative released (module generator):
http://www.yiiframew...sion/modulegen/
0

#2 User is offline   Eliovir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 17-January 09

Posted 04 January 2010 - 03:00 AM

I have done a little dirty thing like this, without FK fields, for Yii 1.0:
class TableData extends CActiveRecord {
        private static $tableName;

        public function __construct($attributes=array(), $scenario='') {
                if (self::$tableName === null) {
                    throw new CDbException(Yii::t('main', '"TableData" requires a "tableName" property.'));
                }
                parent::__construct($attributes, $scenario);
        }

        public static function model($className=__CLASS__) {
                return parent::model($className);
        }

        /**
         * @return string the associated database table name
         */
        public function tableName() {
                return self::$tableName;
        }
        public static function setTableName($tableName) {
                if (! in_array($tableName, self::$db->schema->tableNames)) {
                        throw new CDbException(Yii::t('main', 'Table "{table}" does not exist.', array('{table}'=>$tableName)));
                }
                self::$tableName = $tableName;
        }

        /**
         * @return array validation rules for model attributes.
         */
        public function rules() {
                $rules = array();
                $required = array();
                foreach (self::$db->schema->getTable($this->tableName())->columns as $col) {
                        if (!$col->allowNull) {
                                $required[] = $col->name;
                        }
                }

                if (count($required) > 0) {
                        $rules[] = array(join(', ', $required), 'required');
                }
                return $rules;
        }

        /*
         * @todo relations()
         */
}


and in the controller:
        /**
         * Defines table on which work
         */
        private function setTable() {
                $table = _request('table');
                if ($table) {
                        TableData::setTableName($table);
                        return $table;
                }
                return null;
        }


in the view, the main part is _form.php, needs also to be enhanced
<?php foreach ($columns as $column=>$props):
if ($props['dbType'] == 'geometry') {
        continue;
}
?>
<div class="simple">
<?php echo CHtml::activeLabelEx($model, $column); ?>
<?php echo CHtml::activeTextField($model, $column); ?>
</div>
<?php endforeach;?>


Maybe Yii 1.1 with CActiveDataProvider or http://www.yiiframew...aydataprovider/ can do this more easily.
0

#3 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 04 January 2010 - 06:02 AM

realy Thanks, Analizing testing... AND working in the search feature

:)
trying build code for Generate complete CRUD source code with YII... any help?
post comments here:
EXTENDING CRUD GENERATION (scaffolding)

old tentative released (module generator):
http://www.yiiframew...sion/modulegen/
0

#4 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 04 January 2010 - 07:39 AM

working with the command line tool CRUD, renamed to crud2
trying build code for Generate complete CRUD source code with YII... any help?
post comments here:
EXTENDING CRUD GENERATION (scaffolding)

old tentative released (module generator):
http://www.yiiframew...sion/modulegen/
0

#5 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 04 January 2010 - 05:42 PM

initial code:
this code loockup all tables on the DB that have a relationship with the fields of specific table, that automatically generate the array relational rules.

for
	public function relations()
	{
		return array();
	}

<?
/* coded by Max Rivera */
$con=mysql_connect('localhost','cpga_sis','******');
$db=mysql_select_db('cpga_sis',$con);

function ltable()
	{
	global $db;
	$sql = mysql_query("SHOW TABLE STATUS");
	while($linha = mysql_fetch_assoc($sql)):

    $r[pkey($linha[Name])]=$linha[Name];
    $q[$linha[Name]]=pkey($linha[Name]);
	endwhile;
    $x[0]=$r;
    $x[1]=$q;
    return $x;
    }

function pkey($tabela)
	{
		global $db;
		$query="DESC {$tabela}";
		$results=mysql_query($query);
			while ($row=mysql_fetch_array($results))
			{
			if ($row[Key]=="PRI")
			    {
				return $row[Field];
				}
			}
		return false;
	}

function fk($tabela)
   {
	$chaves=ltable();
	$pkey=pkey($tabela);
	$query="DESC {$tabela}";
	$results=mysql_query($query);
	while ($row=mysql_fetch_array($results))
	{
		if(in_array($row[Field],$chaves[1]) AND $row[Field]!=$pkey)
	    { 
            $s=$chaves[0][$row[Field]];
		    $arr[$s]=$row[Field];
	    }
	}
		$r ="array(";
		foreach($arr as $tabela=>$pk)
		{
		
		$r .= "'".$tabela."'=>array(self::BELONGS_TO, '".$tabela."','".$pk."'),";
		
		}
		$r .=")";

   	return $r;
  }

$tabela='usuario';
print_r(fk($tabela));

?>

result:
 array( 'lab'=>array(self::BELONGS_TO, 'lab','lab_id'),
	'grupo'=>array(self::BELONGS_TO, 'grupo','grupo_id'),

      )


trying build code for Generate complete CRUD source code with YII... any help?
post comments here:
EXTENDING CRUD GENERATION (scaffolding)

old tentative released (module generator):
http://www.yiiframew...sion/modulegen/
0

#6 User is offline   thyseus 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 300
  • Joined: 18-April 09
  • Location:Leipzig, Germany

Posted 06 January 2010 - 04:57 AM

I have translated the (few) Strings used in the default crud Generator to german a while ago.

I think it makes sense to provide a set of default crud pages per language, rather than making
the crud generator i18n-capable, consider this:

crud model style=default lang=de js=active

or

crud model style=futuristic lang=gb js=inactive

to get the crud command some more abilities.

In addition to this it would be cool if the yii-crud would get more intelligent deploying database rows, for example an boolean or tinyint(1) field should be generated as a checkbox; foreign key relations should get be generated as an combobox, date and timestamp to a datepicker (when js is enabled), and so on...

Maybe we build something like this for yii 1.2 :)
0

#7 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 06 January 2010 - 08:36 AM

I have builded all you are saying (90%) but for yii 1.0

now I am rewrinting all for yii 1.x but I have some dificult becouse the developers has changed the parsing method for generate crud (templates and php code)...

:)
trying build code for Generate complete CRUD source code with YII... any help?
post comments here:
EXTENDING CRUD GENERATION (scaffolding)

old tentative released (module generator):
http://www.yiiframew...sion/modulegen/
0

#8 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 06 January 2010 - 08:05 PM

this is wonderfull....
screencast code generator...

http://www.symfony-p...admin-generator
trying build code for Generate complete CRUD source code with YII... any help?
post comments here:
EXTENDING CRUD GENERATION (scaffolding)

old tentative released (module generator):
http://www.yiiframew...sion/modulegen/
0

#9 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,020
  • Joined: 30-October 09
  • Location:UK

Posted 07 January 2010 - 12:13 PM

yii crud tool should generate different input field types depending on the field - not just text fields.
0

#10 User is offline   megabr 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 23-March 09
  • Location:Brazil

Posted 08 January 2010 - 08:03 AM

View PostGSTAR, on 07 January 2010 - 12:13 PM, said:

yii crud tool should generate different input field types depending on the field - not just text fields.


yii crud not generate relations on non fk fields
yii crud not generate loockup for dropdown list from another table
the views list manage in admin group_id is show 3, as better is group:Admin
date fields not have pickup date, enum fields is ignored, bolean ignored, etc....

YII crud is a baby.... simpony is "the man scaffolding", that we need all together work to modify the actual crud method for yii...


:)
trying build code for Generate complete CRUD source code with YII... any help?
post comments here:
EXTENDING CRUD GENERATION (scaffolding)

old tentative released (module generator):
http://www.yiiframew...sion/modulegen/
0

Share this topic:


Page 1 of 1
  • 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