Part of the EllisLab Network
   
2 of 5
2
CodeCrafter 0.3.0 (BETA) - CRUD Source Code generator for CodeIgniter released
Posted: 09 March 2007 04:41 AM   [ Ignore ]   [ # 16 ]  
Lab Assistant
RankRank
Total Posts:  253
Joined  03-06-2007

Sorry just couldn’t see that.

Its a very good idea to have something like this especially for me.

I have tried it a few times this morning and there are a few problems.

Do you want me to post what I find.

Thanks

 Signature 

EE2: 2.0.1 Beta - Build: 20100215
MSM: 2.0 - Build: 20100215
EE2 Forum: 3.0.1 - Build: 20100215
nifootball.co.uk

Profile
 
 
Posted: 09 March 2007 04:55 AM   [ Ignore ]   [ # 17 ]  
Research Assistant
RankRankRank
Total Posts:  558
Joined  06-17-2006

Please do, so we could improve the product.

Or you could send me a private message with the list if you wish. Just press the PM button under my name.

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 09 March 2007 05:10 AM   [ Ignore ]   [ # 18 ]  
Lab Assistant
RankRank
Total Posts:  253
Joined  03-06-2007

Its working ok now, not sure what I selected differently this time.

If I see the error again I will let you know.  It was when I chose a relationship.

 Signature 

EE2: 2.0.1 Beta - Build: 20100215
MSM: 2.0 - Build: 20100215
EE2 Forum: 3.0.1 - Build: 20100215
nifootball.co.uk

Profile
 
 
Posted: 09 March 2007 05:28 AM   [ Ignore ]   [ # 19 ]  
Lab Assistant
RankRank
Total Posts:  253
Joined  03-06-2007

I seem to be just asking stupid questions.

But how to you use the layout, so I can have the header and footer included.

 Signature 

EE2: 2.0.1 Beta - Build: 20100215
MSM: 2.0 - Build: 20100215
EE2 Forum: 3.0.1 - Build: 20100215
nifootball.co.uk

Profile
 
 
Posted: 09 March 2007 06:08 AM   [ Ignore ]   [ # 20 ]  
Research Assistant
RankRankRank
Total Posts:  558
Joined  06-17-2006

Aah. The header and footer are automatically included (but not in appmain - I can;t recall why I did it like that).

Browser to one of your controllers. For example, if you generated code for a table user, then use:
http://mydomain.com/user/

(If you got appmain working, then you should see a menu on the left hand side of the screen. Click of browse for one of your tables.)

You should be viewing the table grid screen (using http://mydomain.com/user/). This file includes the header and footer.

To customise the haeder and footer, change the contents of system/application/views.site/header.php and system/application/views.site/footer.php as you wish.

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 09 March 2007 06:14 AM   [ Ignore ]   [ # 21 ]  
Lab Assistant
RankRank
Total Posts:  253
Joined  03-06-2007

I see now.

As you can tell I am new to this and just learning the ropes, before I convert my app.

Many Thanks

Scott

 Signature 

EE2: 2.0.1 Beta - Build: 20100215
MSM: 2.0 - Build: 20100215
EE2 Forum: 3.0.1 - Build: 20100215
nifootball.co.uk

Profile
 
 
Posted: 29 March 2007 05:26 AM   [ Ignore ]   [ # 22 ]  
Summer Student
Total Posts:  1
Joined  03-29-2007

Hi,
I tried CodeCrafter 0.3 with latest (for today) CodeIgniter version 1.5.2,
but get error about undefined site_url() function in codecrafter_new.php.

I’m totally new to CI, but found a solution:

in the beginning of file added loading of “URL” helper:

<?php $this->load->helper('url'); ?>

Was it right way to fix?

Profile
 
 
Posted: 29 March 2007 07:04 AM   [ Ignore ]   [ # 23 ]  
Research Assistant
RankRankRank
Total Posts:  558
Joined  06-17-2006

yes. or you could autoload the url helper in the application/config/autoload.php file.

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 26 April 2007 09:07 PM   [ Ignore ]   [ # 24 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  137
Joined  02-04-2007

Took me a while to find this thread. The wiki link isn’t working!

Where would be a good place to report bugs, send code improvements and make suggestions for CodeCrafter.

Well until then here is one bug report:

In the models limit clause

This:

if ($start) {
            
if ($count) {
                $limit_clause
= " $start, $count ";
            
}
            
else {
                $limit_clause
= " $start ";
            
}
        }

Should be like this:

if ($start !== NULL) {
            
if ($count) {
                $limit_clause
= " Limit $start, $count ";
            
}
            
else {
                $limit_clause
= " Limit $start ";
            
}
        }

Because just ($start) ignores the value 0 (Zero)
And without ‘Limit’ you will get an sql error.

 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
 
 
Posted: 26 April 2007 10:00 PM   [ Ignore ]   [ # 25 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  137
Joined  02-04-2007

Here is an improvement suggestion:

With this improvement you can use one model for all your code and you don’t need to create a separate model for each database.
I use a class that I call the Master_Model see below.
I usually still have stuff in the custom model but the thinks you need in every model or in many models are in the Master_Model class.

Model:

class Bb_Model extends Master_Model

    
function __construct()
    
{
        parent
::Model();
        
$this->mdb->initdb();
    
}

    
function findWhat($what_rules = NULL) {
        
if($what_rules !== NULL){
            $this
->what= " $what_rules ";
        
}else{
            $this
->what= ' * ';
        
}
    }
$sql = 'SELECT '.$this->what.' FROM '. $this->table . $this->where . $this->limit;

        
$query = $this->db->query($sql);
        
        if (
$query->num_rows() > 0) {
            
foreach ($query->result_array() as $row)
            
{
                $row
= delids($row);
                
$results[] = $row;
            
}
        }

Controller:

function __construct() {
    $this
->table = 'bb_event';
    
$this->load->model('Master_Model', 'mdb');
    
$this->load->model('bb_model', 'bbm')
}

function browse() {
    $this
->bbm->findWhat('Title, Postcode, Starts, Ends, Active');
}


Master_Module

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
class
Master_Model extends Model {

  
    public
function setTable($master_table)
    
{
           $this
->table = $master_table;
        return
$this->table;
    
}

    public
function checkTable()
    
{
        
If( ! isset($this->table) ){
            redirect
('dbview/pages/error_db', 'location');
        
}else{
            
return $this->table;
        
}
    }

    public
function initdb($id = FALSE)
    
{
        
if($id !== FALSE){
            $this
->dbdata = $this->get_by_id($id);
        
}else{
            $fields
= $this->db->list_fields($this->table);
            foreach (
$fields as $field) $this->dbdata[$field] = '';
        
}
        
return $this->dbdata;        
    
}

    public
function get_by_id($id, $table = FALSE)
    
{
        
If( $table !== FALSE ){ $this->table = $table; }
        $this
->checkTable();
        
$return = array();
        
$query = $this->db->query("SELECT * FROM `" .$this->table. "` WHERE id = '" .$id. "' LIMIT 1");
        
        if (
$query->num_rows() > 0) {
            $return
= $query->row_array();
        
}else{
            $return
= FALSE;
        
}
        
return $return;
    
}

Following I have in a helper file, could also be part of the Master_Model but I keep it as helper in case one day I have a model which does not need the Master_Model so that I still have this array helper available. Hasn’t happened so far.
Helper:

<?php

/************************** START UNSET/DEL IDS ****************************
*  Removes id, *_id and also first and last date fields from database array
****************************************************************************/
function delids($array)
{
    $array
= (array) $array;
    if(isset(
$array[0])){
        
foreach($array as $k => $v){
            $array[$k]
= unsetids($v);
        
}
    }else{
        $array
= unsetids($array);
    
}
    
return $array;
}

function unsetids($array)
{
    $keys
= array_keys($array);
    foreach(
$keys as $v){
        
if($v=='id')unset($array[$v]);
        if(
$v=='last')unset($array[$v]);
        if(
$v=='first')unset($array[$v]);
        if(
$v=='added')unset($array[$v]);
        if(
$v=='updated')unset($array[$v]);
        if(
strstr($v, '_id'))unset($array[$v]);
    
}
    
return $array;
}
/************************** END UNSET/DEL IDS ****************************/
 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
 
 
Posted: 27 April 2007 03:07 AM   [ Ignore ]   [ # 26 ]  
Research Assistant
RankRankRank
Total Posts:  558
Joined  06-17-2006

TaMeR, thanks for the contributions.

The links in the WIKI point to the old forums. I’ll update them.

You could use CI Forge to list bugs etc. This forum has also been used in the past and I’m sure the CI community is happy to have it. wink

Thirdly, I had started to build a single-model solution and you last post makes that possible I’m sure. Thank you.

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 08 June 2007 01:05 AM   [ Ignore ]   [ # 27 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  12-14-2006

Just ran across this, and it looks great. After the tweaks mentioned above, I was able to get CodeCrafter running, but now when I enter in the database info and click “Connect” nothing happens. Any ideas?

Thanks!

Profile
 
 
Posted: 08 June 2007 01:27 AM   [ Ignore ]   [ # 28 ]  
Research Assistant
RankRankRank
Total Posts:  558
Joined  06-17-2006

No, but I’ve make a few bug fixes that I’ll load onto the project page this weekend. Perhaps you wouldn’t mind waiting this then.

However, from a functional point the results of your connect should be displayed in the “Database List” panel on the top of the screen. For example, when I entered an incorrect password, the CI generated error message appeared there.

CodeCrafter uses the prototype library to generate AJAX calls. Do you have prototype installed correctly? Should be in <?= BASEDIR; ?>/js/prototype.js.

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 08 June 2007 01:43 AM   [ Ignore ]   [ # 29 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  12-14-2006

Hi Crafter,

Thanks for your reply. It really seems like it could be a JavaScript error. I just managed to freeze Safari, and I don’t get any errors for a wrong password, etc.

Just to clarify—in the download, it’s assets/prototype.js rather than js/prototype.js right? That’s what I find in the models/codecrafter.php too.

I don’t mind waiting. Thanks for your work!

UPDATE: I just knocked out my .htaccess rewrite file (removing index.php) and it started working! Do you see why this would be a problem? Now, time to dive in…

UPDATE #2: DUH, have to make an exception for “assets”!!!

Profile
 
 
Posted: 27 June 2007 07:43 PM   [ Ignore ]   [ # 30 ]  
Summer Student
Total Posts:  4
Joined  06-25-2007

Hi Crafter,

found another little bug, I think.

This error message comes up if generating the code with using of ActiveRecord:

Use of undefined constant ...

Please change in file model_activerecord.src in the lines 113 and 143 from:

$query = $this->db->get( [[table]] );

to:

$query = $this->db->get( '[[table]]' );


thanks a lot, well done work, proceed ...  grin

Profile
 
 
   
2 of 5
2
 
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: 119812 Total Logged-in Users: 42
Total Topics: 125952 Total Anonymous Users: 3
Total Replies: 662645 Total Guests: 427
Total Posts: 788597    
Members ( View Memberlist )