四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

PHP開源開發(fā)框架ZendFramework使用中常見問題說明及解決方案

MVC 代碼書寫:
控制器代碼書寫:

復(fù)制代碼 代碼如下:
<?php
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)容:

復(fù)制代碼 代碼如下:
$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里面去

復(fù)制代碼 代碼如下:
//配置數(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

復(fù)制代碼 代碼如下:
<?php
class Message extends Zend_Db_Table
{
protected $_name ="message";
protected $_primary = 'id';
}
?>

模塊實例化:

復(fù)制代碼 代碼如下:
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): ?>
<tr>
<th><?php echo $message['title']; ?></th>
<td><?php echo $message['content']; ?></td>
</tr>
<?endforeach; ?>

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

復(fù)制代碼 代碼如下:
<?php if(2==2):?>
kk
<?php else:?>
ll
<?php endif;?>

index.phtml里面加上

復(fù)制代碼 代碼如下:
<a href="<?php echo $this->baseUrl?>/index/exit">編輯</a>
<a href="<?php echo $this->baseUrl?>/index/delete">刪除</a>

添加一個新的方法:edit.phtml

復(fù)制代碼 代碼如下:
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ù)成功!<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):

復(fù)制代碼 代碼如下:
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (index.php)' in

解決辦法:在index.php中的

復(fù)制代碼 代碼如下:
$frontController =Zend_Controller_Front::getInstance();后加上
$frontController->setParam('useDefaultControllerAlways', true);

*******
id/3 等于以前的?id=3

php技術(shù)PHP開源開發(fā)框架ZendFramework使用中常見問題說明及解決方案,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 爸爸别走歌曲原唱| 李美琪主演的电影| 女生被艹在线观看| 分家协议| call me by your name电影| 监禁时间2| 四 电影| 老爸老妈浪漫史第一季| 特级做a爰片毛片免费看108| 贾宏| 山东卫视节目表| river flows in you钢琴谱| 黄色网址在线免费播放| 鲁滨逊漂流记阅读笔记| 粉嫩在线| 少女集中营阅读| bbb.| 魔界王子免费动漫观看| 《欢·爱》郭晓东| 67pp| 日本大片网址| 敦煌夜谭在线观看| 侦探们的镇魂歌国语版在线观看| 庞敏| 红色诗词六年级下册| 亲吻姐姐ova| 八年级英语阅读理解专项训练| 黄网站免费观看视频| 妻子的秘密免费观看全集| 夜的命名术动漫| 六一儿童节对联七字| 四川地图旅游地图| 诗妍| 六年级上册美术教案人教版| 电影绿色地狱| 强电影| 员工的秘密| 小学一年级古诗《风》| 我想成为影之强者第三季| 混凝土结构设计规范gb50010-2020| 卧虎在线观看|