EXTENDING CRUD GENERATION (scaffolding)

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

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.yiiframework.com/extension/arraydataprovider/ can do this more easily.

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

:)

working with the command line tool CRUD, renamed to crud2

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'),


      )




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

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)…

:)

this is wonderfull…

screencast code generator…

http://www.symfony-project.org/screencast/admin-generator

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…

:)