Welcome Guest, Not a member yet? Register   Sign In
CI generator for crud (bash and php) 0.1
#1

[eluser]Vlad0[/eluser]
Hi,
this is more idea then ignited code but there is and some code Smile
Before few days I tried symfony for the first time. For me it is too complicated and I like more CI Smile but symfony have nice code generator so I tried to make something similar for CI.

First I made bash script for creating models that I use for every table (cicrud.sh)

then I realized that is better to use php so I made almost same php script but now I'm planing to create with it models, controllers and views. Currently only generating models work.

(cicrud.php)

This is how I use models (basic get/save/delete) but it is very simple to modify for your needs.

So what you think? any suggestions?
#2

[eluser]MikeHibbert[/eluser]
Hey Vlad0

I have been having a go as this is just the sort of thing I like about rails that wish CI had.

Just noticed there is a error on line 17 of every controller made as there is a missing ';' on the end of the line.

Also, on the save method of the model it doesn't insert the new values but inserts a blank record.

I will be adding to this script my self as I'm gonna find it really useful, would you welcome my changes if I post them here?

Mike
#3

[eluser]Vlad0[/eluser]
Hi Mike.
it was double ; on line 139 cicrud.php

of course you can post your changes... Thats why I put it here Smile
#4

[eluser]MikeHibbert[/eluser]
Ok here goes!

This has the errors removed and the fields added to the insert.

I have a library I wrote that can make a form based on what mysql says the fields are. I recon it could help making the views. It at least will create a basic input form for a starting point.

Mike
#5

[eluser]MikeHibbert[/eluser]
I was also thinking that this could be dropped into the root of the CI folder and could be called from the root folder like:

Code:
./cicrud/cicrud [options] [tablename] [feilds]

this is how it works with rail actually.

Mike
#6

[eluser]Vlad0[/eluser]
[quote author="MikeHibbert" date="1229122035"]Ok here goes!

This has the errors removed and the fields added to the insert.

I have a library I wrote that can make a form based on what mysql says the fields are. I recon it could help making the views. It at least will create a basic input form for a starting point.

Mike[/quote]

Can you share with us that library?
On my development and production servers insert works without putting one more array... just like update..
#7

[eluser]MikeHibbert[/eluser]
hmm I always assumed you had to pass an array to that function lol I'm not sure why ?!?!?

Actually, I'm gonna include the library into the system when I get a chance so I will post it later today along with some changes I have made

Mike
#8

[eluser]MikeHibbert[/eluser]
Ok I think I have this working Big Grin

first off I changed the place you put it to inside the root like so:

path-to-ci-folder/crud/create

so now all you need to do is go to the folder and type:

php crud/create [options] [tablename] [fields]

with the 'all' option selected you get the following:

1 controller with list(index), add, edit & delete methods
1 method that can insert, update & delete records
1 folder in 'views' thats named after the table and has add, edit & list veiws that can be loaded along with you headers and footers etc.

this tested and worked fine on my staging server.

so here is a workflow:

Code:
1) drop the crud folder in the root of your ci folder
2) create you table in phpmyadmin or whatever you do it with
3) open your commandline and go to the ci folder of choice
4) type 'php crud/create a mytable name address (whatever your tables fields are basically)

you can do this as many times as you have tables Big Grin

Please test this and give feedback if you can

Mike
#9

[eluser]MikeHibbert[/eluser]
Ok I've been thinking and have come up with some ideas;

What do you think about maybe adding something to the column names that could be stripped off at execution to give info about what the form fields would be created as.

For example:

Code:
php crud/create a tablename normal:name text:address date:DOB

this could then create a set of SQL to create/alter the table we associated with this crud set with.

the one thing i dont have clue about is things like select menus and radio groups in forms and how we could include this in the commandline.

In rails there is a yml file that gives a definition of the form and data sources for such things,

Anyway, just thoughts I hope will be useful Big Grin

Mike
#10

[eluser]Dreammaker[/eluser]
Mike, maybe yml will be good choice for CI too?
Like for rails, for symfony, etc...

***
Vlad and Mike, thanks for good start! I think many CI-people want a working smart and clear crud Smile




Theme © iAndrew 2016 - Forum software by © MyBB