Home php教程 php手册 ZendFramework使用中常见相关问题

ZendFramework使用中常见相关问题

Jun 13, 2016 am 09:33 AM
k

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过来的值.就增加.否则就显示增加页面


}
}
?>
控制当中写内容:$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
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');//显示模版
}

messages as $message): ?>






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


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);
//更新数据
$message->update($set,$where);
unset($set);
echo '修改数据成功!返回';
}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 '删除数据成功!返回';
}


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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Adjust Windows 10 resolution to 2K Adjust Windows 10 resolution to 2K Jan 15, 2024 am 09:57 AM

The win10 system is a personalized system that can carry out various settings and adjustments. Today, the editor brings you the win102k resolution adjustment tutorial! If you are in need, come and have a look. Win102k resolution adjustment tutorial: Note: If you want to set the resolution to 2k, you need the support of computer hardware. 1. Use the shortcut key "Win+i" to open Windows Settings. In the Windows Settings window, click the "System" option to open it. 2. Select Display on the left side of the system interface, and you can see the "Resolution" function settings on the right page. 3. Find the advanced scaling settings and click on it to set the resolution according to your needs! After selecting, click OK to save. (Editor’s email

Does 4790k support win10 system? Does 4790k support win10 system? Jan 06, 2024 pm 10:21 PM

Maybe many old computer users are still using the 4790k CPU, and facing this processor, many netizens don’t know whether it can also support the win10 system, so the answer is given below. Let’s find out whether the 4790k supports the win10 system. Does 4790k support win10 system? Answer: 4790k supports win10 system. 4790k can actually be installed regardless of win10 or win7. 4790k is the strongest hardware platform for win7, and it is also a strong ddr3 game platform. Users who need to change the system may wish to download win10 and try it. More introduction to the win10 system: 1. The win10 system has free channels, and you can access them for free.

Don't want to be eliminated? Learn these PHP development skills and it's no longer difficult to get 10K Don't want to be eliminated? Learn these PHP development skills and it's no longer difficult to get 10K Sep 09, 2023 pm 04:55 PM

Don't want to be eliminated? Learn these PHP development skills and earn 10K is no longer difficult. With the rapid development of the Internet, the field of web development has become a popular choice for high-paying employment. As a widely used server-side scripting language, mastering PHP development skills is crucial for those who want to stand out in the field of web development. This article will introduce some methods to improve PHP development skills, and attach code examples to help readers better understand and master these skills. Familiar with the PHP framework. In PHP development, the framework is to improve development efficiency.

Top 10 virtual currency trading app rankings Top 10 virtual currency trading app recommendations Top 10 virtual currency trading app rankings Top 10 virtual currency trading app recommendations Mar 19, 2025 pm 05:18 PM

This article lists the top ten recommended virtual currency trading apps, including OKX, Binance, Gate.io, Kraken, Huobi, Coinbase, KuCoin, Crypto.com, Bitfinex and Gemini, with no particular order. These platforms have their own advantages in liquidity, security, currency selection, handling fees and user experience. For example, OKX is known for its strong liquidity and convenient user interface, Binance is known for its largest transaction volume and rich learning resources in the world, and Gate.io attracts users with its low handling fees and rich currency selection. To choose a virtual currency trading platform, you need to consider security, liquidity, handling fees, currency selection, and use

Top exchange ranking Top exchange ranking Mar 14, 2025 pm 06:03 PM

Based on eight dimensions of security, liquidity, transaction fees, user experience, currency selection, trading functions, reputation and innovation capabilities, this article deeply analyzes the world's leading cryptocurrency exchanges, and selects the top 3 rankings of Binance, Ouyi and Sesame Open. The ranking takes into account factors such as the exchange's trading volume, trading product diversity, user friendliness, as well as security and regulatory compliance. The article will analyze the advantages and disadvantages of each exchange in detail, and provide selection advice for different types of investors (novice, professional traders, etc.) to help you choose the most suitable cryptocurrency trading platform. Please note that cryptocurrency investment is high in risk. This article is for reference only and does not constitute investment advice.

What are the top ten apps in the currency exchange? What are the top ten apps in the currency exchange? Mar 04, 2025 pm 11:00 PM

Currency exchanges are the main platform for people to buy and sell cryptocurrencies, and choosing a reliable and highly respected exchange is crucial. This article will explore the ten most popular currency exchanges in the industry and conduct a detailed analysis of their transaction volume, fees, security and functions.

Top 10 trading apps virtual currency platforms in the currency circle 2025 authoritative ranking list Top 10 trading apps virtual currency platforms in the currency circle 2025 authoritative ranking list Feb 14, 2025 pm 05:09 PM

The top ten cryptocurrency exchanges in the world include: Binance, OKX, Gate.io, Coinbase, FTX, Huobi, Kraken, Crypto.com, KuCoin and Bitfinex. Each exchange has its advantages, disadvantages and potential problems, such as a large user base, low transaction fees, security, regulatory compliance issues and a single point of failure risk posed by the centralized nature.

How to play the primary market of virtual currency? How to play the primary market of virtual currency? Mar 04, 2025 pm 03:45 PM

This article introduces several main gameplays in the primary market of virtual currency, including private equity financing, pre-sales, angel round financing and market making, and explains in detail the mechanism, risks and potential benefits of each gameplay. The article provides corresponding suggestions for investors with different risk tolerance and investment experience. In addition, the article also recommends several well-known virtual currency primary market trading platform APPs, such as Binance Launchpad, OKX Jumpstart, Gate.io Startup, KuCoin Spotlight, Huobi Prime and MEXC Pioneer, and briefly analyzes the characteristics of these platforms to facilitate investors to choose the right platform to invest.

See all articles