Part of the EllisLab Network
   
1 of 2
1
SparkPlug - Rails inspired Scaffolding
Posted: 03 February 2008 03:41 PM   [ Ignore ]  
Moderator
Avatar
RankRankRankRankRank
Total Posts:  2828
Joined  01-07-2008

A nice Scaffolding library is one thing I was looking forward to in 1.6, especially since the existing one is now deprecated.

Since that didn’t happen, I decided to see how much I could get done in one weekend.  This is the result of that weekend project.
Mind you, it’s not anywhere near being finished, but it works, which was the weekend goal.

Currently it consists of two files.  One for dynamic scaffolding, very much like what already exists.  The other one generates the scaffold code very similar to what rails does when you execute: ./script/generate scaffold Table Controller

I hate the code most applications generate, simply because I like to follow my own coding style.  And changing all the curly braces every time gets really annoying.  So drawing from personal experience, I added templates to the generator (at the bottom of the file).

Eventually I would like to consolidate the two files, and figure out how much of the code they can share, but for now it’s easier to keep them seperate.

I’m not happy with all of it yet, especially the views need work, but the weekend is over and I have to get something out the door.

Get it here: SparkPlug
Don’t forget to read the wiki page.  Tested on OS X with MAMP, please check the paths before running it - just to be sure.

Any feedback is appreciated.

 Signature 
Profile
MSG
 
 
Posted: 03 February 2008 06:40 PM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  2264
Joined  07-30-2007

Definitely looking forward to trying this out. Might I make another suggestion for SparkPlug - Rails inspired migrations.

It makes developing with multiple developers so much easier…

 Signature 

Become a fan of the CodeIgniter Cookbook (estimated: Fall 2010).

Follow me on twitter here.
MichaelWales.com | MichaelWales.info

Profile
 
 
Posted: 03 February 2008 07:01 PM   [ Ignore ]   [ # 2 ]  
Moderator
Avatar
RankRankRankRankRank
Total Posts:  2828
Joined  01-07-2008

Hmm, hadn’t thought of that.  With the addition of the dbforge it wouldn’t be too hard to implement.  I’ll definitely keep that in mind as I clean up the existing code.

 Signature 
Profile
MSG
 
 
Posted: 04 February 2008 01:15 PM   [ Ignore ]   [ # 3 ]  
Grad Student
Avatar
Rank
Total Posts:  60
Joined  01-09-2007

I like the idea of “coding-style” templates….wish I’d have thought of that one.

I’m big on not forcing people to live by “your” decisions and leaving things as open as possible…the style templates adds another level of freedom there.

Do you provide a way to edit what gets generated or how it gets implemented?

 Signature 

http://ignition.lifewithryan.com—CI Code Generation
http://pol.itik.us—Political Social Network written in CI
http://www.lifewithryan.com—My Blog spam wink

Profile
 
 
Posted: 04 February 2008 01:56 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  840
Joined  02-05-2007
Michael Wales - 03 February 2008 06:40 PM

Definitely looking forward to trying this out. Might I make another suggestion for SparkPlug - Rails inspired migrations.

It makes developing with multiple developers so much easier…

Clemens tackled Rails inspired migrations. He called it PHake. I haven’t tried it and development seems to have stalled: http://blog.hyperblast.at/2007/04/21/introducing-phake/

 Signature 

“I am the terror that flaps in the night”

Profile
 
 
Posted: 04 February 2008 04:16 PM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRank
Total Posts:  2828
Joined  01-07-2008
lifewithryan - 04 February 2008 01:15 PM

Do you provide a way to edit what gets generated or how it gets implemented?

This is a concept I’ve been struggling with.  For example the basic show view on the released version right now looks like this:

<? foreach ($fields as $field): ?>
<p>
    <
b><?= ucfirst($field->name) ?>:</b> <?= $result[0][$field->name] ?>
</p>
<? endforeach; ?>
<?
= anchor("scaffold_test/show_list", "Back") ?>

I’ve changed that to only loop through the result array with a foreach (result as key => value) loop, thus eliminating the need to ask for the meta data (which was basically just a dirty hack to get views to work on sunday night wink ).  The other option is to change the function completely and resolve the loop when the code is generated.  It’s very much personal preference.  What do you guys use in your production code?

Since I already have basic variable tags in my views, some clever coding might allow for modifiers to ‘choose’ eventually.  It’s not one of my priorities though.

 Signature 
Profile
MSG
 
 
Posted: 05 February 2008 07:41 PM   [ Ignore ]   [ # 6 ]  
Moderator
Avatar
RankRankRankRankRank
Total Posts:  2828
Joined  01-07-2008

Sorry for the double post, I just want to ‘announce’ an update that, to me, marks the beginning as a usable library - without any of the weekend hacks.  And I’ve started creating some decent documentation on the google code wiki.

The changes are too many to list, and don’t belong here.  Refer to the Change Log.

I highly suggest you read the developer information in the wiki if you want to hack around the code (and who doesn’t wink ), it gives a little clearer overview of what’s going on.

Thanks for all the valuable feedback.

 Signature 
Profile
MSG
 
 
Posted: 10 February 2008 06:43 PM   [ Ignore ]   [ # 7 ]  
Grad Student
Rank
Total Posts:  33
Joined  02-10-2008

Hello

I really like your scaffolding.
I have only really used the scaffolding function so far and not the generate but I have made a few changes.
Where can I send the file??

The biggest change is in retrieving the field details from the DB.
//$fields = $this->CI->db->field_data($this->table);
$fields = $this->_db_get_fields();

I have created a new function to get better info about the field types eg enum - and I have added those to the _insertMarkup and _editMarkup functions.

I also put the 1.6 Scaffolding styles into your _header function.

I also changed the field labels from ucfirst($field->name) to ucwords(str_replace(“_”, ” “, $field->name))

I can’t remember if I made any other small changes but you could tell using a diff anyway.

I really like your class and how simple it is to get going.

Another feature I think it requires is a “confirm” on deleting records.
After that - to make it a really good start for a backend system would be to try to get the relations between tables to work.


I hope that you continue to develop this class - if you would like help let me know because I think I will try to build on what you started.

Best regards
Sean

 Signature 

Thanks
Vas

Profile
 
 
Posted: 10 February 2008 07:47 PM   [ Ignore ]   [ # 8 ]  
Moderator
Avatar
RankRankRankRankRank
Total Posts:  2828
Joined  01-07-2008

Hey Sean,

First off, thanks for you interest.  I would love to see the changes you’ve made.  For now, the file should fit into a pm attachment, and we’ll work something out for anything beyond that.  I do plan on actively developing this library, but I’m nearing finals time so updates will be slow for the next 2 or 3 weeks.

cheers

 Signature 
Profile
MSG
 
 
Posted: 11 February 2008 04:14 AM   [ Ignore ]   [ # 9 ]  
Grad Student
Rank
Total Posts:  33
Joined  02-10-2008

Sent that now.
Thanks

 Signature 

Thanks
Vas

Profile
 
 
Posted: 01 June 2008 04:48 PM   [ Ignore ]   [ # 10 ]  
Summer Student
Total Posts:  1
Joined  05-27-2008

Hi,

I would like to thank you for the library. So simple, yet so useful.

Regards,

Douglas

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120337 Total Logged-in Users: 55
Total Topics: 126462 Total Anonymous Users: 3
Total Replies: 665012 Total Guests: 456
Total Posts: 791474    
Members ( View Memberlist )