Home > php教程 > PHP开发 > body text

MayFish PHP MVC architecture development framework

黄舟
Release: 2016-12-14 13:22:15
Original
2661 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 example is:

Copy the code 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
/**adding data*/
$data = array(
'title' => 'Write test',
'body' => 'Written content' ,
);
$result = $db_test->create($data);
if(FALSE != $result)
{
dump("

exampel 1:
Data written successfully!

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

exampel 2:
");
$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'= >'data4', 'body'=>'content4'),
array('title'=>'data5', 'body'=>'content5'),
);
foreach ($data as $item)
{
$result = $db_test->create($item);
if(FALSE != $result)
{
dump("data".$item[' title']."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:
Data updated successfully !

");
}
/**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 'Access default event | Access event admin | Access event info';
}
}
?>

Thank you for reading, please pay attention to PHP for more related articles Chinese website (m.sbmmt.com)!

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template