Part of the EllisLab Network
   
 
CodeCrafter 02.2 - CRUD Source Code generator for CodeIgniter released
Posted: 24 October 2006 08:18 PM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  558
Joined  06-17-2006

Version 0.2.2 of CodeCrafter is ready for download:
http://www.datacraft.co.za/codecrafter/

This version offers some improvements on and fixes to the previous version. In particular;
  - Form field type customisation to allow control of form field types
  - Advanced option to write output to disk, screen, or both!
  - Use $this->input->post() instead of $_POST in generated model source.
  - Added $query->num_rows() checks after db queries in generated model source.
  - New navigator code to browse generated code.
  - Generated views code now resides in table specific directory.

I’m still driven by the quest to keep this application simple. so you can still generate code for an entire application by just a single mouse click. The added complexities are available for those who need it.

<EDIT>

This version was created on CI 1.3.3 and then tested on CI 1.4.0.2 without any problems.

This version is distributed with the config files for CI 1.4.0.2. To get it run on earlier version, you need to extract:
- The controller, libraries, views, script, init directories.
- The config/application.php file from the config directory.

The download directory contains versions for both CI 1.4.0.2 and CI 1.4.1. Choose the one that matches your version.

</EDIT>

Tell me what you think.

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 25 October 2006 06:54 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  303
Joined  10-17-2006

This version is compatible with 1.5 or 1.4 or both? More information would be useful.

Profile
 
 
Posted: 25 October 2006 07:42 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  558
Joined  06-17-2006
nmweb - 25 October 2006 06:54 AM

This version is compatible with 1.5 or 1.4 or both? More information would be useful.

Good point. I’ve updated the main post with this info.

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 26 October 2006 07:55 PM   [ Ignore ]   [ # 3 ]  
Grad Student
Rank
Total Posts:  44
Joined  09-20-2006

a cool addition to your post would be a more detailed information about it; e.g. usage examples, which needs it can fill etc. As a begginer of CI and advanced PHP coder with lesser time to browse and more to code, I don’t like to install and experiment it to see what it actually does.

Profile
 
 
Posted: 26 October 2006 09:34 PM   [ Ignore ]   [ # 4 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  7337
Joined  03-23-2006
obsesif - 26 October 2006 07:55 PM

a cool addition to your post would be a more detailed information about it; e.g. usage examples, which needs it can fill etc. As a begginer of CI and advanced PHP coder with lesser time to browse and more to code, I don’t like to install and experiment it to see what it actually does.

Here’s a chunk from the download, I hope its helpful.  I’ve not implemented CodeCrafter, but I admire the effort very much.  Thanks Crafter.

Derek

How it works
——————

You enter the values for the database that you wish to generate code for, press
the Submit button and that’s it!

The CodeCrafter reads the details you supplied and creates the resulting code
under your Code Igniter application directory.

CodeCrafter will generate a directory structure for the generated code and place
the code there. It will refuse to recreate directories that already exist, but you
can overwrite this option.


Starting CodeCrafter
——————————

Invoke the codecrafter method by typing the ffg url in your browser.
    http://www.mydomain.com/codecrafter/
  or
    http://www.mydomain.com/codecrafter/codecrafter/
   
You will be presented with a form that prompts you for information about your database.

If you wish to generate source for the entre database:
  - Enter the server, username, password and database name
  - Click the button that say ‘Go ahead. Make my code’
 
If you wish to generate source for the specific database:
  - Enter the server, username, password and database name
  - Click the ‘advanced tab’
  - Enter the table name
  - Click the button that say ‘Go ahead. Make my code’
 
If you can’t remember what database and tables you have.
  - Enter the server, username, password
  - Click the ‘advanced tab’
  - Click the ‘Fetch tables for me’
    - This will query the database for all tables that are available to the specified
    user.
    - The table name will appear in a new panel to the right of the database info panel
  - Click on the databse name you want to work with.
    - The database name will be automatically filled in the database info panel
    - All tables from your selected database will be displayed in a panel to the right
      of the database panel
  - Click on the table name you require.
    - The database and table name will be automatically filled in the database info panel
    - All fiels from your selected table will be displayed in a panel below the database
      and table panels
  - Set the field specifications as desired.
  - Click the button that say ‘Go ahead. Make my code’

Note:
  The fetch tables only works for Mysql since CI does not currently offer meta data for
  databases.

Setting field options
——————————————
1. Currently, if you wish to customise the field options for selected tables, you can
  only do that ONE TABLE AT A TIME. CodeCrafter WILL NOT allow you to customise field
  options for more than one table in your selected database at a time. This will be
  addressed in a future version.


More on the Advanced Options
——————————————
1. Check the ‘Overwrite Protection’ to prevent CodeCrafter from overwriting existing
  directories. FILES IN THE DIRECTORIES WILL BE OVERWRITTEN. Tread carefully.
2. You can now output your generated code to:
  * Disk
  * Screen
  * Both disk and screen
3. The ‘Create Navigator’ option will create a navigation system to allow you to browse
  your selected code. This can form the skeleton for your own navigation system.
  See http://css.maxdesign.com.au/listamatic/

 

Using your code
————————
The generated code can be found here (obviously the directory names are configurable):
    [ci_system_directory]/application/crud_ouput/
    [ci_system_directory]/application/crud_ouput/table_name/   
    [ci_system_directory]/application/crud_ouput/table_name/controllers/
    [ci_system_directory]/application/crud_ouput/table_name/views/
    [ci_system_directory]/application/crud_ouput/table_name/models/[[table_name]]

Copy the generated code to your own aplications directory,

Invoke the new controller methods

Enjoy


About the Generated Code
————————————-

Code is generated for the views, controllers and models.

CodeCrafter uses templates to assist with the code generation. The templates can
be found in the CodeCrafters view/template directory (Not the generated code!).

If you wish to change portions of the code, you can do that.

The tenplate uses placeholders in the following format
  [[placeholder_name]]

Some of the more abvious ones
  - [[component]]      - The table name
  - [[class]]          - The table name with first letter in Caps
  - [[modelname]]      - The table name with first letter in Caps + ‘model’ appended
  - [[primary_key_value]]  - PK for the table
  - [[table]]          - Guess!!

Note:
——-
I have in mind to rationalise and centralise this list of placeholder variables, so they will
probably change in time. So tread carefully of you are playing with them.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 31 October 2006 08:17 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  558
Joined  06-17-2006

I’ve created a user guide for CodeCrafter and loaded that onto the download area. Format is PDF. I’ll rekease an OpenDocument format once I’ve cleaned up the document and brought the size down a bit.

Get the user guide at http://www.datacraft.co.za/codecrafter/

As usual, I appreciate your feedback.

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 02 November 2006 08:02 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  10-31-2006

Let me begin by saying CodeCrafter is a dandy tool, I’m using it to help me learn various aspects of Code Igniter.

While I have many questions, I’m for the most part getting answers by trial and error.

Which brings me to ask some that cannot be answered by that method. smile

The Layout Model, now I’m new to the whole MVC thing, but it seems to contradict the Model function in that it accesses the Views directly without a controller doing its bidding.

Is this accepted practice? and will it always be acceptable to do it that way?

I ask because I liked where you are going with the Layout Model, and thought it could be worthy of continued attention and use.

And some small issues I’ve discovered.
Also I’m using php5, not sure yet if that is why, but the comment in the grid views

<!--<DIV ALIGN='center'>
      
<?= /*$page_links; */ ?>
    
</DIV>-->

produces a php error.

In the Controllers, this

$config['total_rows'] = count(array_slice($the_results, 0, 1));
does not seem to get the total records, so I did this
$config['total_rows'] = $this->barstockmodel->total_rows;
and added this
$this->total_rows = $this->db->count_all('barstock');
and this
var $total_rows;

into the model, while the solution may not be proper, it helped in my understanding of what was supposed to happen.

George

Profile
 
 
Posted: 03 November 2006 11:40 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
RankRankRank
Total Posts:  558
Joined  06-17-2006

The Layout Model, now I’m new to the whole MVC thing, but it seems to contradict the Model function in that it accesses the Views directly without a controller doing its bidding.

Is this accepted practice? and will it always be acceptable to do it that way?

I ask because I liked where you are going with the Layout Model, and thought it could be worthy of continued attention and use.

Actually the layout model is just a hangup from a previous “roll your own” model that I was using. Is hould probably have been a library, but was easier to implement as a model. In addition, I liked keeping libraries away from application specific data, which in my own applications the layout model used heavily (fro example reading menu config from the database based on login etc.

I was thinking about converting this to a library in a future version. How do you see it unfolding?

With regards your $total_rows issue, I swear it worked when I tried it. wink .

I’ll look again at the code and test properly. The reason I use this is because of the peculiar way that the retrievelist() function in the models return the data. I can’t remember the details now but returning $query->result_array() from the models was not working for me in populating the grid. It is an area that I plan to revisit.

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 03 November 2006 03:00 PM   [ Ignore ]   [ # 8 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  10-31-2006
Crafter - 03 November 2006 11:40 AM

Actually the layout model is just a hangup from a previous “roll your own” model that I was using. Is hould probably have been a library, but was easier to implement as a model. In addition, I liked keeping libraries away from application specific data, which in my own applications the layout model used heavily (fro example reading menu config from the database based on login etc.

I was thinking about converting this to a library in a future version. How do you see it unfolding?

With regards your $total_rows issue, I swear it worked when I tried it. wink .

I’ll look again at the code and test properly. The reason I use this is because of the peculiar way that the retrievelist() function in the models return the data. I can’t remember the details now but returning $query->result_array() from the models was not working for me in populating the grid. It is an area that I plan to revisit.

Well from the whole MVC point of view, it might be better as a library, and in the long run less confusing, having read through the library documentation it seem that it would be acceptable to have the Layout rendering class there.

And it does not break my mind when wrapping it around the whole MVC thing. smile

Well it reality, the total rows needs to take into account the query without the limit to properly count the max returned rows, but that’s easy enough to fix. smile


George

Profile
 
 
Posted: 04 November 2006 02:56 PM   [ Ignore ]   [ # 9 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  10-31-2006

I copied your layoutmodel.php to the application libraries folder and named it Layout.php

BTW, I’m using CI 1.5

and made the following changes.

<?

class Layout {

var $current_module;


    function
render_page($template, $data) {
        $obj
=& get_instance();

       
// Get the configured skin. or use the default
       
$skin = $obj->config->item('skin');

       if (
$skin == '' ) {
          $skin
= 'default';
       
}


    $header_items
= array();
    
$main_contents = array();

    
// Populate the dynamic header items entries
    // $header_items['field1'] = 'some_value';
    // $header_items['field2'] = 'some_value';
    
    
$main_contents['page_contents'] = $obj->load->view("$template", $data, true);
    
// If you need to set other variables not passed from controller, do that here
    // $main_contents['leftmenuitems'] = 'Some value here';
    // $main_contents['module'] = 'Some value here';
    
    // TODO: Make the layout processing more generic. (Use $skin, etc)
    // TODO: Set the header in the app config
    
$layout_components['header'] = $obj->load->view('/site/header', $header_items, true);

    
$layout_components['contents'] = $obj->load->view('/site/main', $main_contents, true);

    
// TODO: Set the header in the app config   
    
$layout_components['footer'] =  $obj->load->view('/site/footer', '', true);

    
$obj->load->view('site/layout', $layout_components);

    
}

}

?>

and in the controller:

// $this->load->model('layoutmodel');                  // Instantiate the model
      
$this->load->library('layout');

and changed other references from layoutmodel to layout.

And it works!

So it’s a good starting point.

George

Profile
 
 
Posted: 21 April 2007 12:14 PM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  137
Joined  02-04-2007

I just tried codecraft version 3.0 beta.
This guy is on to something.
Once you generated your site you still have a lot of editing to do but it beets what I been going with my loops and stuff to shorten code.

The code you get from codecraft is a great base to start.
I wish there was a possibility to save your selections so you could go back and make changes without having to redo the whole thing but I guess thats all still to come.

That Layout.php is nonsense I think
I would just add a header and a footer call in the view pages and be done with it,

<?php $this->load->view('layout/header');?>
// View stuff here!!!
<?php $this->load->view('layout/footer'); ?>

The html stuff is not to the new code should be all lover case

<th VALIGN='MIDDLE' ALIGN='CENTER'  class='tbl_headercell'>


Well I like to close with a big thank you great job!

 Signature 

TaMeR

This is my CodeIgniter web site. If you see something you like/need let me know.
PzzAzz Mobile Advertising

Be who you are and do what you do for those who mind do not matter and those that matter do not mind!

Profile
 
 
   
 
 
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: 120524 Total Logged-in Users: 35
Total Topics: 126590 Total Anonymous Users: 5
Total Replies: 665515 Total Guests: 397
Total Posts: 792105    
Members ( View Memberlist )
Newest Members:  AmityBetbulJahhnvicrussell@gmail.comdefrtymusclesseownikaiyuharry295tanyagrey312