Skip to content
Jacky Jiang edited this page Jul 31, 2014 · 1 revision

Welcome to the ActiveFrame wiki!

This is a simple document covers all basics you need to know to get started.

1. Controller

The name of the controller class must start with 'C_'.

2. DB Class

2.1 CSearcher

2.1.1 To Search Record

$s=new CSearcher($table);//--Create object of the CSeacher class. $table is a string of the name of the table which you want to search on.
$s['name']='tom'; //-- search records which 'name' data field is equal to 'tom';
$s->setFetchDataSet('id, name'); // fetch only these fields
$records=$s->fetchResult();//--fetch all records matching the conditions
$records=$s->fetchPlainArray(); //--fetch all records matching the conditions as a plain array such as mysql_fetch_assoc returns

2.1.2 Update Record

$records[0]['name']='Jim'; //--change the 'name' data field of the first record to 'Jim'
unset($records); //--- Optional step. changes will be sent to database when object is about to be removed from memory or end of the program

2.1.3 Delete Record

$s=new CSearcher($table);//--Create object of the CSeacher class.
$s['name']='tom'; //-- search records which 'name' data field is equal to 'tom';
$records=$s->fetchResult();//--fetch all records matching the conditions
$records[0]->delete(); // delete the first record of these
unset($records); //-- changes will be sent to database when object is about to be removed from memory

2.1.4 Create Record

$record=new CActiveRecord($table); //---$table is a string of the name of the table which you want to create record on.
$record['name']='Jim'; //--set the 'name' data field of the new record to 'Jim'
unset($record); //-- record will be created when object is about to be removed from memory

OR

$record->insert_id(); // record will be automatically committed to database when try to get the ID of inserted row

2.2 Operate on database using SQL statement

global $APP_ENV;
$db=$APP_ENV['db'];
$records=$db->fetchResultBySQL($sql); //---$sql is the sql statement you want to execute. UPDATE, INSERT ... will return an empty array

3. View files

3.1 Include templates

{template PATH_TO_SUB_TEMPLATE} //--PATH_TO_SUB_TEMPLATE is the a path to the sub template file

3.2 Output variables

$a //--- output variable $a

3.3 Control operators

<!--{loop $records $record_id $record_value}-->
HTML content
<!--{/loop}-->

This produces a similar outcome to php code:

foreach($array as $key=>$value)

or simpler

<!--{loop $records $record}-->
HTML content
<!--{/loop}-->

3.4 Language Marks

3.4.1 load language keyword xxx

{lang xxx}

3.4.2 load language keyword by variable

suppose

$v=’xxx’;
{lang $v}

This is equal to

{lang xxx}

3.5 Load Formatter

<!--{loadFormatter xxxx}-->