Welcome Guest, Not a member yet? Register   Sign In
Simple tool for Scaffolding to manage all tables faster
#12

[eluser]eljunior[/eluser]
oh, no! I already forgave you once, now I'll have to forgive you one more!

correcting my english is ok, but assuming I'm spanish... (soy brasileño, ¡hombre viejo! Smile pero no te preocupes, me gustaría mucho ser uruguayo... :-D y mi nombre es "Elias Junior", por eso "eljunior". ;-))

thanks for the corrections, it actually looks funnier when corrected... Smile

well, since you seems to use CI seriously and I've got your attention, I'd like some
advice in the following (I know it's not the appropriate thread, but if this turns in
something good, we'll create a thread for it):

I wanted to be able to use a dropdown for the foreign keys in scaffolding,
so I created this method in system/scaffolding/Scaffolding :

Code:
function _prepare_field_data($field_data)
        {
                foreach($field_data as $i => $field){
                        $table=null;
                        if(ereg('_id$',$field->name)){ // matches table_id
                                $table=ereg_replace('_id$','',$field->name);
                        }
                        if(ereg('^id_',$field->name)){ // matches id_table
                                $table=ereg_replace('^id_','',$field->name);
                        }
                        if(! ($table && $this->CI->db->table_exists($table)) ){
                                continue; // isn't a reference, skip it
                        }

                        $options = array(); // sets up an array of options
                        $query=$this->CI->db->get($table);
                        foreach($query->result_array() as $row){
                                // this assumes that first field is id,
                                // followed by a field description
                                $options[ current($row) ] = next($row);
                        }

                        $field_data[$i]->options=$options;
                        // changes field type for testing in the view
                        $field_data[$i]->type='reference';
                }
                return $field_data;
        }

and called it from methods add:
Code:
'fields' => $this->_prepare_field_data($this->CI->db->field_data($this->current_table)),

and in method edit:
Code:
'fields'        => $this->_prepare_field_data($query->field_data()),

and finally added an elsif in the views for showing the dropdown:
Code:
<?php elseif ($field->type == 'reference'): // cont. acoxambre EDSJ ?>
        <td>&lt;?  echo form_dropdown($field->name,$field->options); ?&gt;</td>

now, I want to know if this thing is a good practice, if there are problems in this approach
or if it makes sense to have something like this in CI and if CI is likely to have something like that, and if it can be good just for me, or if you could use something like this,
and probably more questions, depending on your answer... :-D

¡muchas gracias, muchacho!
y ¡feliz navidad! :-D


Messages In This Thread
Simple tool for Scaffolding to manage all tables faster - by El Forum - 11-23-2007, 07:27 PM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 11-26-2007, 02:54 PM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 11-29-2007, 08:55 AM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 11-29-2007, 10:10 AM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 11-29-2007, 10:51 AM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 12-22-2007, 02:05 AM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 12-22-2007, 05:31 PM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 12-22-2007, 06:25 PM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 12-22-2007, 09:44 PM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 12-23-2007, 09:38 AM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 12-24-2007, 10:01 PM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 12-24-2007, 11:00 PM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 12-27-2007, 11:08 AM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 12-27-2007, 11:40 AM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 01-05-2008, 04:39 AM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 01-21-2008, 07:46 PM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 11-18-2010, 11:55 PM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 11-19-2010, 08:17 AM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 01-04-2011, 10:27 PM
Simple tool for Scaffolding to manage all tables faster - by El Forum - 01-07-2011, 08:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB