Framework workflow:
Loading framework file loading parameter setting object initialization setting loading project setting parameters getting controller and Controller Method execute controller events
Example:
Copy codeThe 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 codeThe 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