Zend Framwork 第一个实例

创建 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 }?>


应该可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值