php常见问题及其解决方案,PHP开源开发框架ZendFramework使用中常见问题说明及解决方案...
mvc 代碼書寫:
控制器代碼書寫:
class indexcontroller extends zend_controller_action
{
function init()
{
$this->registry = zend_registry::getinstance();
$this->view = $this->registry['view'];
$this->view->baseurl = $this->_request->getbaseurl();
}
function indexaction()
{
$this->view->word=" i love spurs";
echo $this->view->render("index.html");
}
function addaction(){
//如果是post過來的值.就增加.否則就顯示增加頁面
}
}
?>
控制當(dāng)中寫內(nèi)容:
$this->view->word="ggg";
$this->view->render("index.html");
---->index.html echo $this->word;
application->config.ini
[general]
db.adapter=pdo_mysql
db.config.host=localhost
db.config.username=root
db.config.password=
db.config.dbname=think_zw
配置文件引入到framework里面去
//配置數(shù)據(jù)庫參數(shù),并連接數(shù)據(jù)庫
$config=new zend_config_ini('./application/config/config.ini',null, true);
zend_registry::set('config',$config);
$dbadapter=zend_db::factory($config->general->db->adapter,$config->general->db->config->toarray());
$dbadapter->query('set names utf8');
zend_db_table::setdefaultadapter($dbadapter);
zend_registry::set('dbadapter',$dbadapter);
單一入口模式:localhost/index/add/訪問index模塊下的add方法
function addaction(){}(在indexcontroller.php)
默認(rèn)訪問為index模塊下的index方法
再建立一個模塊model里面的message.php
class message extends zend_db_table
{
protected $_name ="message";
protected $_primary = 'id';
}
?>
模塊實例化:
function indexaction()
{
$message=new message();//實例化數(shù)據(jù)庫類
//獲取數(shù)據(jù)庫內(nèi)容
$this->view->messages=$message->fetchall()->toarray();
echo $this->view->render('index.phtml');//顯示模版
}
<?foreach ($this->messages as $message): ?>
<?php echo $message['title']; ?><?php echo $message['content']; ?>*************
修改和刪除數(shù)據(jù)
kk
ll
index.phtml里面加上
編輯
刪除
添加一個新的方法:edit.phtml
function editaction(){
$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);
//更新數(shù)據(jù)
$message->update($set,$where);
unset($set);
echo '修改數(shù)據(jù)成功!返回';
}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 '刪除數(shù)據(jù)成功!返回';
}
異常出現(xiàn):
fatal error: uncaught exception 'zend_controller_dispatcher_exception' with message 'invalid controller specified (index.php)' in
解決辦法:在index.php中的
$frontcontroller =zend_controller_front::getinstance();后加上
$frontcontroller->setparam('usedefaultcontrolleralways', true);
*******
id/3 等于以前的?id=3
希望與廣大網(wǎng)友互動??
點此進(jìn)行留言吧!
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的php常见问题及其解决方案,PHP开源开发框架ZendFramework使用中常见问题说明及解决方案...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php文件怎么阅读器,Vue文件阅读器组
- 下一篇: lotus php,LotusPhp笔记