ZendFramework使用中常见问题
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使用中常见问题的更多相关文章
- VMware使用中常见问题
1.NAT模式下,主机与虚拟机可以相互ping通,但虚拟机无法上网 解决办法:a.设置主机网络属性如下图所示,允许网络共享.
- Vue使用中常见问题
1.安装sass时报未找到 1.原因应该同时安装:1.npm install --save-dev sass-loader 2.npm install --save-dev node-sass ...
- Robot FrameWork使用中常见问题收集
1.“假死”现象 在完成一个模块的脚本编写后,多次运行没问题,但是隔了几天再来运行的时候,发现脚本运行会出现浏览器那边不动了,脚本这边的时间一直在跑. 问题原因及解决方法: 问题解决了,原因是**dr ...
- ajax上传文件以及使用中常见问题处理
<script src="/scripts/ajaxfileupload.js"></script> <script src="/scrip ...
- appium+python+iOS 环境搭建与使用中常见问题的解决方案链接
(1)WebDriverAgent 安装入门篇:https://www.cnblogs.com/zhanggui/p/9239827.html 重点摘要: 在WDA的Github上也给出了WDA的特性 ...
- Git 常用命令行
最近在公司的服务器上安装了Git Sever,开始从SVN转向到Git了,整理了一些在Git常用的命令. 取得Git仓库 初始化一个版本仓库 git initClone远程版本库 git clone ...
- svn工具的使用问题总结
前言: 最近在开发的时候,由于需求太多,开发周期长短不一,从主线上切了多个分支(一般不在主线trunk上开发,万一线上出问题可及时修改代码上线),在部分功能上线后,想把代码同步到新的分支上去,最开始的 ...
- Spark- 常见问题
记录spark使用中常见问题 SparkSQL 日期解析时用到SimpleDateFormat, SimpleDateFormat是线程不安全的.可以使用 FastDateFormat 如: impo ...
- Java中数组要点总结
1.数组是基本数据类型和字符串类型的容器(引用数据类型),而集合是类数据类型的容器: 2.数组定义的格式: (1)一般格式: 元素类型[] 数组名 = new 元素类型[元素个数或者数组长度]: 其中 ...
随机推荐
- Linux中的文件压缩,打包和备份命令
压缩解压命令 gzip 文件 -c : 将压缩数据输出到屏幕,可用来重定向 -v 显示压缩比等信息 -d 解压参数 -t 用来检验一个压缩文件的一致性看看档案有没错 -数字 : 压 ...
- storm单机版安装配置
1,install zeromq 期间可能出现:configure: error: cannot link with -luuid, install uuid-dev. 因此可以先安装 sudo ap ...
- jetty之建立多Connector
转自:http://blog.csdn.net/kongxx/article/details/7218787 在嵌入运行Jetty的时候,有时候想要启动两个端口,或者通过一个Jetty server提 ...
- java消息队列使用场景
http://blog.163.com/sir_876/blog/static/11705223201332444647261/ 目前能用到的比较不错的消息队列组件 ,kafka,activeMq, ...
- The server quit without updating PID file (mysql.pid)一次意外mysql停止运行备忘录
[root@iZ23tsvd9h4Z ~]# service mysqld status ERROR! MySQL (Percona Server) is not running, but lock ...
- android 嵌套 apk 从一个apk启动另外一个apk
a.apk-主应用 b.apk-被启动应用 主要思想:把b.apk放到assets目录下,由于有大小限制(1M),所以改名成b.mp3(因为mp3,jpg,png,mp4等不会检查,不会限制大小), ...
- [Webpack 2] Polyfill Promises for Webpack 2
If you're going to use code splitting with Webpack 2, you'll need to make sure the browser has suppo ...
- [React] React Fundamentals: Build a JSX Live Compiler
we want to have the ability to write JSX and see the output live in the browser. <!doctype html&g ...
- 3第一周课后练习·阅读计划(2)-使用指针来访问私有数据成员
/* * Copyright (c) 2015, 计算机科学学院,烟台大学 * All rights reserved. * 文件名:test.cpp * 作 靠:刘畅 * 完成日期:2015年 3 ...
- 一大波Java来袭(二)异常处理
概要解析: 本章的知识点能够记为:1图+5keyword+先逮小的.后逮大的 一.基础 (一)定义 1.异常 是指在程序执行的时候发生的一些异常事件.良好的程序设计应该在异常发生的时候提供处理异常的 ...