日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php常见问题及其解决方案,PHP开源开发框架ZendFramework使用中常见问题说明及解决方案...

發(fā)布時間:2023/12/19 php 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php常见问题及其解决方案,PHP开源开发框架ZendFramework使用中常见问题说明及解决方案... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。