创建 zf.bat create project D:\PHPBack\ZFTest D:\PHPBack为全路径 ZFTest 为项目名
将Zend Framwork Libery 文件夹复制到项目的Libery 中
其他配置完成后 打开页面 就可以看到ZF的欢迎界面
连接数据库
在configs 下的application.ini 配置
[mysql]
db.adapter = PDO_MYSQL
db.params.host = localhost
db.params.username = root
db.params.password = *****
db.params.dbname = patientmanager
在Bootstrap.php中初始化适配器
function __construct($app)
{
parent::__construct($app);
//初始化适配器
$url=constant("APPLICATION_PATH").DIRECTORY_SEPARATOR.'configs'.DIRECTORY_SEPARATOR.'application.ini';
$dbconfig=new Zend_Config_Ini($url,"mysql");
$db=Zend_Db::factory($dbconfig->db);
$db->query('SET NAMES UTF8');
Zend_Db_Table::setDefaultAdapter($db);
}
在models 中 创建 model
<?php
class Patientinfo extends Zend_Db_Table //一定要继承zend_db_table
{
protected $_name='patientinfo'; //表名
protected $_primary='PatientID'; //主键
}
?>
在indexcontroller 中 引入model
require_once APPLICATION_PATH .'/models/Patientinfo.php';
在indexAction 中使用model
$patientinfoModel=new Patientinfo();
$res=$patientinfoModel->fetchAll()->toArray();
$this->view->res=$res;
$this->render('index');
在index.phtml 中调用查询到的结果
<?php foreach ($this->res as $patientinfo) {?>
<?=$patientinfo['PatientID']?><br>
<?php }?>
应该可以了