PHP开源开发框架ZendFramework使用中常见问题说明及解决方案
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(); } echo $this->view->render("index.html"); }
控制当中写内容: 代码如下: $this->view->word="ggg";
$this->view->render("index.html"); ---->index.html echo $this->word; application->config.ini 配置文件引入到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方法 再建立一个模块model里面的message.php 代码如下: class Message extends Zend_Db_Table
{ protected $_name ="message"; protected $_primary = 'id'; } ?> 模块实例化: 代码如下: function indexAction()
{ $message=new message();//实例化数据库类 //获取数据库内容 echo $this->view->render('index.phtml');//显示模版 messages as $message): ?> ************* 代码如下: kk ll index.phtml里面加上 代码如下: baseUrl?>/index/exit">编辑
baseUrl?>/index/delete">删除 添加一个新的方法:edit.phtml 代码如下: function editAction(){
$message = new Message(); if(strtolower($_SERVER['REQUEST_METHOD'])=='post'){ $set = array(
if($id > 0){ 异常出现: 代码如下: 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); ******* (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |