Framework workflow:
Loading framework file loading parameter setting object initialization setting loading project setting parameters getting controller and Controller Method execute controller events
Example: CopyCode The Code is as follows: <? PHP
Class defaultcontroller extends appcontroller
{
Protected $ components = array ('smarty ');
/** Default event (method )*/
Public Function Index ()
{
$ Db_test = m ('members '); // load and instantiate a model
/** Add data */
$ DATA = array (
'Title' => 'write test ',
'Body' => 'written content ',
);
$ Result = $ db_test-> Create ($ data );
If (false! = $ Result)
{
Dump ("<p> <strong> exampel 1: </strong> <br/> data is written successfully! </P> ");
}
/** Add multiple data entries */
Dump ("<p> <strong> exampel 2: </strong> <br/> ");
$ DATA = array (
Array ('title' => 'data 1', 'body' => 'content 1 '),
Array ('title' => 'data 2', 'body' => 'content 2 '),
Array ('title' => 'data 3', 'body' => 'content 3 '),
Array ('title' => 'data 4', 'body' => 'content 4 '),
Array ('title' => 'data 5', 'body' => 'content 5 '),
);
Foreach ($ data as $ item)
{
$ Result = $ db_test-> Create ($ item );
If (false! = $ Result)
{
Dump ("Data <strong>". $ item ['title']. "</strong> write successful! <Br/> ");
}
}
Dump ("</P> ");
/** Update data */
$ DATA = array ('title' => 'modify data title', 'body' => 'modify data content ');
$ Result = $ db_test-> where (Array ('id' => 3)-> Update ($ data );
If (false! = $ Result)
{
Dump ("<p> <strong> exampel 3: </strong> <br/> the data is updated successfully! </P> ");
}
/** Delete data */
$ Result = $ db_test-> where ("ID = 5")-> remove ();
If (false! = $ Result)
{
Dump ("<p> <strong> exampel 3: </strong> <br/> the data is deleted successfully! </P> ");
}
/** Execute Data Query and use a coherent operator */
$ Db_test-> where (Array ('id' => 12, 'Action' => 1 ))
-> Order ("'id' DESC ")
-> Fields ("ID, name, Action ")
-> Findall ();
$ This-> shownav ();
}
// Image Processing Event
Public Function image ()
{
$ File = configure: Read ('app _ path'). '/yagas/k750c_small_06.jpg ';
$ Im = m ('sys ', 'image'); // load and instantiate a system model
$ Im-> th_width = 200;
$ Im-> th_height = 150;
$ Im-> thumb ($ file, null, false );
}
/** Another controller event */
Public Function admin ()
{
Dump ($ this );
$ This-> shownav ();
}
/** Another controller event */
Public Function Info ()
{
$ This-> shownav ();
Phpinfo ();
}
/** This is an internal event and cannot be accessed from the browser address */
Private function shownav ()
{
Echo '<a href = "/"> default access event </a> | <a href = "? A = admin "> access event admin </a> | <a href = "? A = Info "> access event info </a> ';
}
}
?>
Implementation of multiple sites in a single space
Copy code The Code is as follows: <? PHP
Header ('content-type: text/html; charset = UTF-8 ');
Include_once ('./mayfish/init. php'); // load the MFs framework
$ Domain = $ _ server ['HTTP _ host'];
Switch ($ domain ){
Case 's1 .xinxi169.com.cn ':
Configure: Write ('app _ name', 'app ');
Configure: Write ('app _ path', dirname (_ file _). '/app ');
Break;
Case 'www .aike8.cn ':
Case 'aike8. cn ':
Configure: Write ('app _ name', 'aike8 ');
Configure: Write ('app _ path', dirname (_ file _). '/aike8 ');
Break;
}
$ APP = new application ();
$ App-> Run ();
?>
Http://www.jb51.net/codes/20169.html