Sunday, January 18, 2009

codeilo_v1beta

codeilo version 1 beta
after re-engineering whole system, I think codeilo can be publish now.
however, I need somebody help to test it and reply me some comment.

download codeilo_v1beta

[Feature for codeigniter]
For codeigniter it generate below items
- CRUD page controller, model and view
- validator for all field based on field type, null value
- index page filter and pager.
- filter by the value of foreign key table field.
- foreign key selection box
- create language file for all table field's label.
- predefine foreign key's display field name.
- predefine input field code.

Thursday, January 1, 2009

How To "display related table field value on View" - second way

refer to "step by step" post.
post table's "sysuser_id" field is a foreign key, which related to sysuser table.

this post show that how to show sysuser table's name field value on post's show record page.

you have 2 way for get sysuser's name.
1. use sysuser options array.
2. left join table when get the record.

second way:
edit the post controller's show function
remove all code which for create sysuser options array.

// sysuser options array
$this->sysuser_id_options=array();
$this->load->model('sysuser_model');
$records=$this->sysuser_model->get_records();
$sysuser_option=array(''=>'');
foreach($records as $record){
$sysuser_option[$record['id']]=$record['id'];
}
$data['sysuser_options']=$sysuser_option;



then change show function's code
form

$data['m']=$this->post_model->get_record_by_pk($m_id);

to

$this->post_model->set_related_table_field('sysuser','sysuser.name as uname');
$this->post_model->add_where(array('post.id'=>$m_id));
$data['m']=$this->post_model->get_record();


change post's view show.php file.
from

<tr>
<th><?php echo form_label('Sysuser Id:', 'sysuser_id'); ?><th>
<td><?php echo $m['sysuser_id']; ?><td>
</tr>

to

<tr>
<th><?php echo form_label('Sysuser Id:', 'sysuser_id'); ?><th>
<td><?php echo $m['uname']; ?><td>
</tr>


that's all

How To "display related table field value on View" - first way

refer to "step by step" post.
post table's "sysuser_id" field is a foreign key, which related to sysuser table.

this post show that how to show sysuser table's name field value on post's show record page.

you have 2 way for get sysuser's name.
1. use sysuser options array.
2. left join table when get the record.

first way:
you can see post controller have " $sysuser_options " assigned to view.
please change post's view show.php file.
from

<tr>
<th><?php echo form_label('Sysuser Id:', 'sysuser_id'); ?><th>
<td><?php echo $m['sysuser_id']; ?><td>
</tr>

to

<tr>
<th><?php echo form_label('Sysuser Id:', 'sysuser_id'); ?><th>
<td><?php echo $sysuser_options[$m['sysuser_id']]; ?><td>
</tr>

than change the controller show function content.
from

// sysuser options array
$this->sysuser_id_options=array();
$this->load->model('sysuser_model');
$records=$this->sysuser_model->get_records();
$sysuser_option=array(''=>'');
foreach($records as $record){
$sysuser_option[$record['id']]=$record['id'];
}
$data['sysuser_options']=$sysuser_option;

to

// sysuser options array
$this->sysuser_id_options=array();
$this->load->model('sysuser_model');
$records=$this->sysuser_model->get_records();
$sysuser_option=array(''=>'');
foreach($records as $record){
$sysuser_option[$record['id']]=$record['name'];
}
$data['sysuser_options']=$sysuser_option;


that's all.