MVC 代码书写:
控制器代码书写:
<?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过来的值.就增加.否则就显示增加页面

}
}
?>
控制当中写内容:$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里面去
//配置数据库参数,并连接数据库
$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)
默认访问为index模块下的index方法

再建立一个模块model里面的message.php
<?php
class Message extends Zend_Db_Table
{
protected $_name ="message";
protected $_primary = 'id';
}
?>
模块实例化:
function indexAction()
{
$message=new message();//实例化数据库类

//获取数据库内容
$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; ?>

*************
修改和删除数据

<?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>

添加一个新的方法: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);
//更新数据
$message->update($set,$where);
unset($set);
echo '修改数据成功!<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 '删除数据成功!<a href="'.$this->view->baseUrl.'/index/index/">返回</a>';
}

异常出现:
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

ZendFramework使用中常见问题的更多相关文章

  1. VMware使用中常见问题

    1.NAT模式下,主机与虚拟机可以相互ping通,但虚拟机无法上网 解决办法:a.设置主机网络属性如下图所示,允许网络共享.

  2. Vue使用中常见问题

    1.安装sass时报未找到 1.原因应该同时安装:1.npm install --save-dev sass-loader    2.npm install --save-dev node-sass ...

  3. Robot FrameWork使用中常见问题收集

    1.“假死”现象 在完成一个模块的脚本编写后,多次运行没问题,但是隔了几天再来运行的时候,发现脚本运行会出现浏览器那边不动了,脚本这边的时间一直在跑. 问题原因及解决方法: 问题解决了,原因是**dr ...

  4. ajax上传文件以及使用中常见问题处理

    <script src="/scripts/ajaxfileupload.js"></script> <script src="/scrip ...

  5. appium+python+iOS 环境搭建与使用中常见问题的解决方案链接

    (1)WebDriverAgent 安装入门篇:https://www.cnblogs.com/zhanggui/p/9239827.html 重点摘要: 在WDA的Github上也给出了WDA的特性 ...

  6. Git 常用命令行

    最近在公司的服务器上安装了Git Sever,开始从SVN转向到Git了,整理了一些在Git常用的命令. 取得Git仓库 初始化一个版本仓库 git initClone远程版本库 git clone ...

  7. svn工具的使用问题总结

    前言: 最近在开发的时候,由于需求太多,开发周期长短不一,从主线上切了多个分支(一般不在主线trunk上开发,万一线上出问题可及时修改代码上线),在部分功能上线后,想把代码同步到新的分支上去,最开始的 ...

  8. Spark- 常见问题

    记录spark使用中常见问题 SparkSQL 日期解析时用到SimpleDateFormat, SimpleDateFormat是线程不安全的.可以使用 FastDateFormat 如: impo ...

  9. Java中数组要点总结

    1.数组是基本数据类型和字符串类型的容器(引用数据类型),而集合是类数据类型的容器: 2.数组定义的格式: (1)一般格式: 元素类型[] 数组名 = new 元素类型[元素个数或者数组长度]: 其中 ...

随机推荐

  1. mongoDB文件太大查错纪录

    日志系统,突然从24号之后的都断层了,交易看不见.查了一下问题是MongoDB把硬盘撑爆了,看了下情况: -bash-3.2$ du -h 82M ./log .1G ./db/journal .0K ...

  2. xom报错 Exception in thread "main" java.net.UnknownHostException: file

    Exception in thread "main" java.net.UnknownHostException: file at java.net.AbstractPlainSo ...

  3. Java Development Kit(JDK) 8 新特性(简述)

    一.接口的默认方法 Java 8允许我们给接口添加一个非抽象的方法实现,只需要使用 default关键字即可,这个特征又叫做扩展方法. 示例如下: interface Formula { calcul ...

  4. PHP开发APP接口(二)

    这里将会调用前面博客的数据库连接单例.文件缓存类和开发APP接口(一) <?php // http://app.com/list.php?page-=1&pagesize=12 requ ...

  5. PAT 1074. Reversing Linked List (25)

    Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elem ...

  6. Java大数类介绍

    java能处理大数的类有两个高精度大整数BigInteger 和高精度浮点数BigDecimal,这两个类位于java.math包内,要使用它们必须在类前面引用该包:import java.math. ...

  7. 在Eclipse上搭建Cocos2d-x的Android开发环境

    很多其它相关内容请查看本人博客:http://www.bokeyi.com/ll/category/cocos2d-x/ 本文的搭建方法是最新最正确的方法,好多朋友反映搭建eclipse交叉编译环境非 ...

  8. struts2 相关知识

    struts2学习笔记 1.struts.properties struts.properties 是可以不要的!!!因为 struts.xml文件中 有 <constant> 这个节点, ...

  9. Java基础知识强化之集合框架笔记53:Map集合之Map集合的遍历 键值对对象找键和值

    1. Map集合的遍历(键值对对象找键和值) Map -- 夫妻对  思路:  A: 获取所有结婚证的集合  B: 遍历结婚证的集合,得到每一个结婚证  C: 根据结婚证获取丈夫和妻子 转换:  A: ...

  10. 测试cnblogs是否存在链接引用的bug

    如果来源页弹出了一个对话框,或者跳转到了本页面,说明来源页面存在链接引用的bug