Home > Backend Development > PHP Tutorial > MayFish PHP MVC architecture development framework_PHP tutorial

MayFish PHP MVC architecture development framework_PHP tutorial

WBOY
Release: 2016-07-21 15:45:24
Original
1274 people have browsed it

Framework workflow:
Load framework file>Load parameter setting object>Perform initialization settings>Load project setting parameters>Get controller and controller method>Execute controller event

Usage examples are:

Copy code The code is as follows:

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' => 'Writing test',
'body' => 'Written content ',
);
$result = $db_test->create($data);
if(FALSE != $result)
{
dump("

< ;strong>exampel 1:
Data written successfully!

");
}
/**Add multiple pieces of data*/
dump( "

exampel 2:
");
$data = array(
array('title'=>'data 1', 'body'=>'Content1'),
array('title'=>'Data2', 'body'=>'Content2'),
array('title'=> ;'data3', 'body'=>'content3'),
array('title'=>'data4', 'body'=>'content4'),
array ('title'=>'Data5', 'body'=>'Content5'),
);
foreach($data as $item)
{
$result = $db_test->create($item);
if(FALSE != $result)
{
dump("data".$item['title']."< /strong>Write successfully!
");
}
}
dump("

");
/**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("

exampel 3:
");
}
/**Delete data*/
$result = $db_test->where("id=5")-> remove();
if(FALSE != $result)
{
dump("

exampel 3:
Data deleted successfully !

");
}
/**Perform data queries using coherent operators*/
$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="/">Access default event | Access event admin | Access event info';
}
}
?>

MayFish PHP MVC architecture development framework_PHP tutorial

MayFish PHP MVC architecture development framework_PHP tutorial

MayFish PHP MVC architecture development framework_PHP tutorial
MayFish PHP MVC architecture development framework_PHP tutorial
Implementation of multiple sites in a single space
Copy code The code is as follows:

header('Content-type:text/html; charset=utf-8');
include_once('./MayFish/init.php'); // Load 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();
?>

Download address http://www.jb51.net/codes/20169.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320382.htmlTechArticleFramework workflow: Load framework file》Load parameter setting object》Perform initialization settings》Load project setting parameters》Get control Controller and controller methods》Execute controller events using...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template