ZendFramework流程
Bootsrap.php内写入:
//启动
function __construct($app) {
parent::__construct($app);
file_put_contents("G:/xampp/htdocs/logs/tZF1/logs.txt",__FILE_.date('Y-m-d H:i:s').'..\r\n',FILE_APPEND);
}
可以在G:/xampp/htdocs/logs/tZF1内产生一个logs.txt文件记录日志信息
数据库连接设置
1.建立信息表message表格
2.htdocs/tZF1/application/models内新建一个message.php即‘表名.php’文件,文件内写
/**
* table_name表CRUD操作
*/
class TableName extends Zend_Db_Table
{
protected $_name = 'table_name';
protected $_primary = 'pk';
function __construct(argument)
{
# code...
}
}
3.htdocs\tZF1\application\controllers\IndexController.php内引入module文件
require_once APPLICATION_PATH.'/models/table_name.php';
...
public function indexAction(){
//到数据库查询
$messageModel = new Message();
$res = $messageModel->fetchAll()->toArray();
echo "<pre>";
print_r($res);
echo "</pre>";
$this->view->res = $res;
$this->render('index');
}
4.htdocs\tZF1\application\configs\application.ini配置数据库信息
[mysql]
db.adapter = PDO_MYSQL
db.params.host = localhost
db.params.username = admin
db.params.password = admin
db.params.dbname = zf
5.htdocs\tZF1\application\Bootstrap.php内初始化适配器
function __construct($app) {
parent::__construct($app);
//初始化适配器
//找到配饰文件
$url = constant("APPLICATION_PATH").DIRECTORY_SEPARATOR.'configs'.DIRECTORY_SEPARATOR.'application.ini';
//读取mysql(与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);
}
6.视图显示数据库信息
htdocs\tZF1\application\views\scripts\index\index.phtml写入
<?php foreach ($this->res as $value) {
echo $value['columns_name']."=".$value['columns_name']."<br>";
} ?>
7.注意 需要开启PDO和PDO相关数据库引擎
在php.ini文件内
extension=php_pdo_mysql.dll\\去掉分号
单入口,重定向
1.\htdocs\tZF1\public.htaccess内配置
RewriteEngine On
#.匹配除\n外所有字符
#设置访问 http://tZF1.com/****都会访问index.php
#即改写为 http://tZF1.com/index.php
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
2.开启Apache 的rewrite模块
在httpd.conf目录下
#启用rewrite功能
LoadModule rewrite_module modules/mod_rewrite.so
- AllowOverride None 全部改写成AllowOverride All
4.说明:rewrite开启后会自动寻找根目录下的.htaccess文件
即:apache内有init() {
//读取httpd.conf // rewrite
//调用rewritemodle
//读取.htaccess
}
配置错误日志
在php.ini内error_log = php_errors.lg配置
error_log = "D:\xampp\htdocs\syslog\phperr.log"
自定义输出日志
file_put_contents('G:/xampp/htdocs/mylog.txt'.__FILE__."\r\n",FILE_APPEND);
PS.
- 控制器action_nameAction(){…}
action_name必需小写 - 若action_namEAction(){…}
http ://tZF1.com/index/action_name
无法匹配,输出htdocs\tZF1\application\views\scripts\error\error.phtml内容 - action_namEAction(){…}
http ://tZF1.com/index/action_namE
报错404 - 数据库引擎 MyISAM不支持外键,但速度略快
InnoDB支持外键
目前使用MyISAM居多