Saturday, July 30, 2011

Slot Helper

Introduction
Symfony Slot like function.
http://www.symfony-project.org/book/1_0/07-Inside-the-View-Layer#chapter_07_sub_slots

Require library
http://codeigniter.com/wiki/layout_library/

Source
helpers/slot_helper.php

<?php
function slot($name){
Slot::setName($name);
ob_start();
}
function end_slot(){
$name=Slot::getName();
Slot::set($name,ob_get_contents());
ob_end_clean();
}
function get_slot($name,$default=''){
return ( Slot::get($name)==false )?$default:Slot::get($name);
}
class Slot{
static $name='';
static $content=array();
static function setName($in){
self::$name=$in;
}
static function getName(){
return self::$name;
}
static function set($key,$val){
self::$content[$key].=$val;
}
static function get($key){
if( !isset(self::$content[$key]) ){
return false;
}
return self::$content[$key];
}
}

?>


Usage

template.php

<html >
<head>
<title><?php echo get_slot('html_title',''); ?></title>
<?php echo get_slot('html_head',''); ?>
</head>
<body>
<?php echo get_slot('html_body',''); ?>
</body>
</html>


view_file.php

<?php slot('html_title'); ?>
I am page title.
<?php end_slot(); ?>

<?php slot('html_head'); ?>
<!-- Hi! This content will be show inside head tag. -->
<script type=\"text/javascript" src="../nav/nav.js"></script>
<?php end_slot(); ?>

<?php slot('html_body'); ?>
Hi! This content will be show inside body tag.
<?php end_slot(); ?>


Output

<html >
<head>
<title>
I am page title.
</title>
<!-- Hi! This content will be show inside head tag. -->
<script type=\"text/javascript" src="../nav/nav.js"></script>
</head>
<body>
Hi! This content will be show inside body tag.
</body>
</html>

Tuesday, July 27, 2010

codeilo_v1beta4.3.zip

- bug fixed. Auto gen select field for Multi Foreign Key
- new feature. schema file.
additional argument schemaonly
"php generator.php schemaonly"
user can edit schema( e.g. foreign key setting) before generate program code.

download

Friday, July 9, 2010

Tuesday, July 7, 2009

codeilo_v1beta4.1.zip bugfix

-bug fix for ajax
-bug fix for select box options

download

Monday, July 6, 2009

version 1 beta 4 (support both ajax and no ajax)

- additional assets file.
- all put into ci application's web folder.

codeilo_v1beta4.zip
Download

Wednesday, July 1, 2009

support ajax

codeilo v1 beta 3

- codeigniter ajax crud mvc template.

http://www.box.net/shared/e0h5pif4eg

Friday, June 26, 2009

enhanced CI pagination

(For codeigniter v1.7.1)
Additional parameter for pager assign href value and onclick function.

{arg} value will be replace by {paging link tag}.
so that if paging link tag is 20.
ci class will output: href="http://sample/page/20"
this class will output: href="http://sample/page/20" onclick="doSomething('20'); return false;"

[sample]
$pagination_config['base_function_name'] = jhistoryList(\'#list/format/html/begin/{arg}\')';
$pagination_config['replace_href_content'] = current_url().'#list/format/html/begin/{arg}';
$this->pagination->initialize($pagination_config);

Download

multilingual supported CI Calendar

(For codeigniter v1.7.1)
Additional parameter for translate calendar's day names and month names.

[sample]
$prefs['translated_day_names'] = array('日', '一', '二', '三', '四', '五', '六');
$prefs['translated_month_names'] = array('01' => '一月', '02' => '二月', '03' => '三月', '04' => '四月', '05' => '五月', '06' => '六月', '07' => '七月', '08' => '八月', '09' => '九月', '10' => '十月', '11' => '十一月', '12' => '十二月');
一月', '12' => '十二月');

$this->load->library('calendar', $prefs);

Download

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.

Tuesday, December 30, 2008

Step by Step

1. create database
CREATE TABLE IF NOT EXISTS `post` (
`id` int(10) unsigned NOT NULL auto_increment,
`sysuser_id` int(10) unsigned NOT NULL,
`title` varchar(100) NOT NULL,
`content` text NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `sysuser` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
`logon` varchar(50) NOT NULL,
`password` varchar(32) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2.
- download program zip file.
- unzip to a folder.


3.
- select your framework's generator (codeigniter_generator.php), also change the the setting.




4.
- run command "php codeigniter_generator.php".


5.
after run "php codeigniter_generator.php", it will create MVC folder and file.
copy to codeigniter controllers, models and views folder.









6.
edit codeigniter
system\application\config\autoload.php
from
$autoload['libraries'] = array();
to
$autoload['libraries'] = array('database');

system\application\config\config.php
$config['base_url'] = "http://{i dont know wo}/";

system\application\config\database.php
$db['default']['username'] = "i dont know wo";
$db['default']['password'] = "i dont know wo";
$db['default']['database'] = "i dont know wo";

system\application\config\routes.php
from
$route['default_controller'] = "welcome";
to
$route['default_controller'] = "sysuser";

7.
list page.



create page.


validator.


foreign key field's selection box.


and ......

Monday, December 29, 2008

Codeilo version 0.97

http://www.box.net/shared/f4ykfpn88m

[STEP BY STEP]
- download program zip file.
- unzip to a folder.
- select your framework's generator, also change the the setting.
- run command "php {your framework name}_generator.php".
for example(codeigniter): php codeigniter_generator.php
- copy the program code files to your framework's folder.
for example(codeigniter):
copy {this program folder}codeigniter_code/models/ all files to {codeigniter}/system/application/models/
copy {this program folder}codeigniter_code/views/ all files to {codeigniter}/system/application/views/
copy {this program folder}codeigniter_code/controllers/ all files to {codeigniter}/system/application/controllers/
- change codeigniter config file autoload.php, config.php and database.php and/or route.php setting.
- you can use it now!