Zend Freamwork配置源码.docx
《Zend Freamwork配置源码.docx》由会员分享,可在线阅读,更多相关《Zend Freamwork配置源码.docx(13页珍藏版)》请在冰豆网上搜索。
ZendFreamwork配置源码
配置目录
Zend框架就放在library中。
根目录.htaccess文件内容
RewriteEngineon
RewriteRule.*index.php
php_flagmagic_quotes_gpcoff
php_flagregister_globalsoff
application目录下.htaccess文件内容
denyfromall
index.php
php
date_default_timezone_set('Europe/London');
set_include_path('.'.PATH_SEPARATOR.'./library'.PATH_SEPARATOR.'./application/models/'.PATH_SEPARATOR.get_include_path());
include"Zend/Loader.php";
Zend_Loader:
:
loadClass('Zend_Controller_Front');
Zend_Loader:
:
loadClass('Zend_Db');
Zend_Loader:
:
loadClass('Zend_Db_Table');
Zend_Loader:
:
loadClass('Zend_Acl');
//设置数据库
$params=array('host'=>'127.0.0.1',
'username'=>'root',
'password'=>'root',
'dbname'=>'zend',
'charset'=>'utf8'
);
$db=Zend_Db:
:
factory('PDO_MYSQL',$params);
Zend_Db_Table:
:
setDefaultAdapter($db);
//设置控制器
$frontContraller=Zend_Controller_Front:
:
getInstance();
$frontContraller->throwExceptions(true);
$frontContraller->setControllerDirectory('./application/controllers');
//Acl
$acl=newZend_Acl();
$acl->addRole(newZend_Acl_Role('guest'));
$acl->addRole(newZend_Acl_Role('user'),'guest');
$acl->addRole(newZend_Acl_Role('admin'),'user');
$acl->add(newZend_Acl_Resource('index'));
$acl->add(newZend_Acl_Resource('work'));
$acl->add(newZend_Acl_Resource('admin'));
$acl->allow('guest','index');
$acl->allow('user','work');
$acl->allow('admin');
$privalege=$acl->isAllowed('guest','index')?
'allow':
'denied';
if($privalege=='denied')
exit('Denied');
//
$frontContraller->dispatch();
?
>
______________________________________________________
IndexController.php
php
classIndexControllerextendsZend_Controller_Action{
functioninit()
{
$this->initView();
$this->view->baseUrl=$this->_request->getBaseUrl();
Zend_Loader:
:
loadClass('Album');
}
functionindexAction()
{
$this->view->title='MyAlbums';
$album=newAlbum();
$this->view->albums=$album->fetchAll();
$this->render();
}
functionaddAction()
{
$this->view->title='AddNewAlbums';
if(strtolower($_SERVER['REQUEST_METHOD'])=='post')
{
Zend_Loader:
:
loadClass('Zend_Filter_StripTags');
$filter=newZend_Filter_StripTags();
$artist=$filter->filter($this->_request->getPost('artist'));
$artist=trim($artist);
$title=$filter->filter($this->_request->getPost('title'));
$title=trim($title);
if($artist!
=''&&$title!
='')
{
$data=array(
'artist'=>$artist,
'title'=>$title,
);
$album=newAlbum();
$album->insert($data);
$this->_redirect('./');
return;
}
}
$this->view->album=newstdClass();
$this->view->album->id=null;
$this->view->album->artist='';
$this->view->album->title='';
$this->view->action='add';
$this->view->buttonText='Add';
$this->render();
}
functioneditAction()
{
$this->view->title='EditnewAlbum';
$album=newAlbum();
if(strtolower($_SERVER['REQUEST_METHOD'])=='post')
{
Zend_Loader:
:
loadClass('Zend_Filter_StripTags');
$filter=newZend_Filter_StripTags();
$id=(int)$this->_request->getPost('id');
$artist=$filter->filter($this->_request->getPost('artist'));
$artist=trim($artist);
$title=$filter->filter($this->_request->getPost('title'));
$title=trim($title);
if($id!
=false)
{
$data=array(
'artist'=>$artist,
'title'=>$title,
);
$where='id='.$id;
$album->update($data,$where);
$this->_redirect('./');
return;
}
else
{
$this->view->album=$album->fetchRow('id='.$id);
}
}
else
{
$id=(int)$this->_request->getParam('id',0);
if($id>0){
$this->view->album=$album->fetchRow('id='.$id);
}
}
$this->view->action='edit';
$this->view->buttonText='Update';
$this->render();
}
functiondeleteAction()
{
$this->view->title='DeleteNewAlbum';
$album=newAlbum();
if(strtolower($_SERVER['REQUEST_METHOD'])=='post')
{
Zend_Loader:
:
loadClass('Zend_Filter_Alpha');
$filter=newZend_Filter_Alpha();
$id=(int)$this->_request->getPost('id');
$del=$filter->filter($this->_request->getPost('del'));
if($del=='Yes'&&$id>0)
{
$where='id='.$id;
$rows_affected=$album->delete($where);
}
}
else
{
$id=(int)$this->_request->getParam('id');
if($id>0)
{
$this->view->album=$album->fetchRow('id='.$id);
if($this->view->album->id>0)
{
$this->render();
return;
}
}
}
$this->_redirect('./');
}
}
?
>
_______________________________________________________
index.phtml
phpinclude('header.phtml');?
>
phpecho$this->escape($this->title);?
>
phpecho$this->baseUrl;?
>/index/add">Addnewalbun
Title | Artist | |
---|
phpforeach($this->albumsAS$album):
?
>
phpecho$this->escape($album->title);? > | phpecho$this->escape($album->artist);? > | phpecho$this->baseUrl;? >/index/edit/id/ phpecho$album->id;? >">Edit phpecho$this->baseUrl;? >/index/delete/id/ phpecho$album->id;? >">Delete
|
phpendforeach;?
>
phpinclude('footer.phtml');?
>
_______________________________________________________
header.phtml
DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http:
//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
//www.w3.org/1999/xhtml">
phpecho$this->escape($this->title);?
>
phpecho$this->baseUrl;?
>/public/styles/site.css"/>
____________________________________________________
footer.phtml