-
Notifications
You must be signed in to change notification settings - Fork 0
cigenerator
CI generator for crud (bash and php) 0.1
cicrud.sh [code] #!/bin/bash
CICRUD 0.1 By Vladimir Grubor ([email protected])
or if your application folder is in system ./cicrud.sh /home/vlado/web/ci/system test username email password status
#Configuration AUTHOR="Vladimir Grubor ([email protected])" DATE=$(date '+%d.%m.%Y %R')
FOLDER=$1
if [ ! -x $FOLDER ]; then
echo 'Error: wrong directory name. Use ./cicrud dirname table field1 field2...'; exit 1
fi
TABLE=$2
MODELNAME="mod$TABLE"
MODEL="$FOLDER/application/models/$MODELNAME.php"
echo "Starting CI-Bash CRUD $DATE"
echo "Table: $TABLE CI Folder: $FOLDER"
#Creating model echo "<?php if (!defined('BASEPATH')) exit('No direct script access allowed');" > $MODEL echo "/**
- $TABLE model
- @author $AUTHOR
- @date $DATE */" >> $MODEL echo "class mod$TABLE extends Model {" >> $MODEL echo '' >> $MODEL echo ' var $id;' >> $MODEL
for thing in "$@"
do
if [ ${thing} !=
echo '' >> $MODEL echo ' var $select;' >> $MODEL echo ' var $limit;' >> $MODEL echo ' var $limit2;' >> $MODEL echo ' var $order;' >> $MODEL
#GET Function
echo '' >> $MODEL
echo " function $MODELNAME(){
parent::Model();
}">>$MODEL
echo '' >> $MODEL
echo " /**
* Return filtered $TABLE
*
* @access public
* @param void
* @return $TABLE
*/" >> $MODEL
echo ' function get(){' >>
#SAVE Function
echo " /**
* Save $TABLE
*
* @access public
* @param void
* @return integer
*/" >> $MODEL
echo ' function save(){' >>
echo ' if ($this->id) {' >> $MODEL echo " $this->db->where('id',$this->id);" >> $MODEL echo " $this->db->update('$TABLE');" >> $MODEL echo " return $this->id;" >> $MODEL echo ' }' >> $MODEL echo ' else {' >> $MODEL echo " $this->db->update('$TABLE');" >> $MODEL echo ' return $this->db->insert_id();' >> $MODEL echo ' }' >> $MODEL echo ' }' >> $MODEL echo '' >> $MODEL echo ' // --------------------------------------------------------------------' >> $MODEL echo '' >> $MODEL
#DELETE echo " /** * Delete row from $TABLE * * @access public * @param integer * @return void */" >> $MODEL echo ' function del($id){' >> $MODEL echo ' $this->db->where('id',$id);' >> $MODEL echo ' $this->db->limit(1);' >> $MODEL echo " $this->db->delete('$TABLE')" >> $MODEL echo ' }' >> $MODEL echo '' >> $MODEL
#Finishing model echo '}' >> $MODEL #echo '?>' >> $MODEL echo "/* End of file $MODELNAME.php /" >> $MODEL echo "/ Location: ./application/models/$MODELNAME.php */" >> $MODEL [/code]
cicrud.php [code] #!/usr/bin/php -q <?
CICRUD 0.1 By Vladimir Grubor ([email protected])
#Configuration
$author = 'Vladimir Grubor ([email protected])'; $cifolder = 'application/'; // or 'system/application/' $date = date('d.m.Y H:i'); // Date time format
#Parms $mvc = $_SERVER['argv'][1]; $folder = $_SERVER['argv'][2]; $folder = $folder.$cifolder; $table = $_SERVER['argv'][3];
function model()
{
global $folder,$table,$author,$date;
$modelname = 'mod'.$table.'.php';
$model = $folder.'/models/'.$modelname;
echo "Generating model...\n";
$fp = fopen($model, 'w');
fwrite($fp, "<?php if (!defined('BASEPATH')) exit('No direct script access allowed');\n");
fwrite($fp, "/\n");
fwrite($fp, "* $table model\n");
fwrite($fp, "\n");
fwrite($fp, " @author $author\n");
fwrite($fp, "* @date $date\n");
fwrite($fp, "*/\n");
fwrite($fp, "class mod$table extends Model {\n");
fwrite($fp, ' var $id'.";\n");
for($i=4;$i<count($_SERVER['argv']);$i++)
{
fwrite(
}
function controller() { global $folder,$table; }
function view() {
}
if ($mvc && $folder && $table) { if (!is_dir($folder)) die("Error: Wrong CI Project folder. Use php cicrud.php [(m)odel|(c)ontroller|(v)iew|(a)ll] [CI project folder] [table] [fields]\n"); if ($mvc == 'm' or $mvc == 'model') model(); else if ($mvc == 'c' or $mvc == 'controller') controller(); else if ($mvc == 'v' or $mvc == 'view') view(); else if ($mvc == 'a' or $mvc == 'all') { model(); controller(); view(); } else die("Error: wrong argument (m) (v) (c) or (a)ll. Use php cicrud.php [(m)odel|(c)ontroller|(v)iew|(a)ll] [CI project folder] [table] [fields]\n"); } else die("Error: no arguments. Use php cicrud.php [(m)odel|(c)ontroller|(v)iew|(a)ll] [CI project folder] [table] [fields]\n"); ?> [/code]