国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

ZendFramework使用中常見問題

2019-11-15 01:38:23
字體:
供稿:網(wǎng)友
ZendFramework使用中常見問題

MVC 代碼書寫:控制器代碼書寫:<?phpclass 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方法

再建立一個(gè)模塊model里面的message.php<?phpclass Message extends Zend_Db_Table{PRotected $_name ="message";protected $_primary = 'id';}?> 模塊實(shí)例化:function indexAction() { $message=new message();//實(shí)例化數(shù)據(jù)庫類

//獲取數(shù)據(jù)庫內(nèi)容 $this->view->messages=$message->fetchAll()->toArray();

echo $this->view->render('index.phtml');//顯示模版 }

<?foreach($this->messages as $message): ?> <tr> <th><?php echo $message['title']; ?></th><td><?php echo $message['content']; ?></td> </tr> <?endforeach; ?>

*************修改和刪除數(shù)據(jù)

<?php if(2==2):?>kk <?php else:?>ll<?php endif;?>

index.phtml里面加上<a href="<?php echo $this->baseUrl?>/index/exit">編輯</a><a href="<?php echo $this->baseUrl?>/index/delete">刪除</a>

添加一個(gè)新的方法:edit.phtmlfunction 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ù)成功!<a href="'.$this->view->baseUrl.'/index/index/">返回</a>'; }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ù)成功!<a href="'.$this->view->baseUrl.'/index/index/">返回</a>'; }

異常出現(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


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 嘉义市| 上饶县| 开原市| 那曲县| 神农架林区| 库车县| 宜章县| 剑河县| 隆回县| 辽阳县| 黄龙县| 蓬莱市| 大城县| 富民县| 长兴县| 腾冲县| 福建省| 龙门县| 湘西| 泌阳县| 彰化县| 沽源县| 大石桥市| 宜阳县| 乡城县| 贵阳市| 新宁县| 枣强县| 兴仁县| 瑞金市| 霍州市| 当雄县| 休宁县| 泽普县| 宜丰县| 松阳县| 宝应县| 湖口县| 乌兰察布市| 丰县| 桐城市|