Home >Backend Development >PHP Tutorial >Description of common problems and solutions in the use of PHP open source development framework ZendFramework_PHP tutorial
MVC code writing:
Controller code writing:
}
function indexAction()
{
$this->view->word=" I love spurs";
echo $this->view->render("index.html");
}
function addAction(){
//If it is the value from POST, increase it. Otherwise, display the increase page
}
}
?>
Writing content in control:
application->config.ini
[general]
db.adapter=PDO_MYSQL
db.config.host=localhost
db.config.username=root
db.config .password=
db.config.dbname=think_zw
Introduce the configuration file into the framework
Single entry mode: localhost/index/add/ access the add method under the index module
function addAction(){} (in IndexController.php)
The default access is the index method under the index module
Create another message.php in the module model
Module instantiation:
//Get database content
$this->view->messages=$message->fetchAll()->toArray();
echo $this->view->render('index.phtml');//Display template
}
messages as $message): ?>
****************
Modify and delete data
Add
in index.phtmlAdd a new method: edit.phtml
$message = new Message();
$db = $message->getAdapter();
if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){
$id = $this->_request->getPost('id');
$cid = $this->_request->getPost('cid');
$title = $this->_request->getPost('title');
$set = array(
'cid'=>$cid,
'title'=>$title
);
$where = $db->quoteInto('id = ?',$id);
//更新数据
$message->update($set,$where);
unset($set);
echo '修改数据成功!返回';
}else{
$id = $this->_request->getParam('id');
$this->view->messages = $message->fetchAll('id='.$id)->toArray();
echo $this->view->render('edit.phtml');
}
}
function delAction(){
$message = new Message();
$id = (int)$this->_request->getParam('id');
if($id > 0){
$where = 'id = ' . $id;
$message->delete($where);
}
echo '删除数据成功!返回';
}
异常出现:
解决办法:在index.php中的
*******
id/3 等于以前的?id=3