zf 从数据库中取出最近三十天的数据并生成柱状图
在终端用cd 命令进入文件目录
说明:此处例子我是拿项目中的一个例子讲解的。
1、新建一个项目 :用终端输入:zf create project Airline 格式:zf create action project project-name 备注:这些格式可以在终端输入zf 查看
2、新建一个action :zf create action dirgramshow index 格式:zf create action action-name controller-name
3、新建一个 model :zf create db-table flightinformation
action 层代码:indexController.php
View Code
1 public function indexAction ()
2 {
3 // action body
4 $db = new Application_Model_DbTable_Flightinformation();
5 /*获取最近30天内的数目
6 * select day(boo_time) as day,count(boo_autoid)as count,boo_time from bookinformation
7 where flag_pass=0 and date_sub(now(), interval 30 day)<=date(boo_time)
8 group by DATE_FORMAT(boo_time,'%m %d')
9 */
10 $sql = "select DATE_FORMAT(boo_time,'%m-%d') as day,count(boo_autoid)as count from bookinformation " .
11 "where flag_pass=0 and date_sub(now(), interval 30 day)<=date(boo_time) " .
12 "group by DATE_FORMAT(boo_time,'%m %d')";
13 $result = $db->getAllInfo($sql)->fetchAll();
14 $this->view->result=$result;
15 }
view 层代码:dirgramshow.phtml
View Code
model 层代码:Flightinformation.php
View Code
1 <?php
2
3 class Application_Model_DbTable_Flightinformation extends Zend_Db_Table_Abstract
4 {
5
6 protected $_name = 'flightinformation';
7
8 public function getAllInfo($sql){
9 $adapter = Zend_Registry::get('db');
10 $flightinformation = $adapter->query($sql);
11 return $flightinformation;
12 }
13 }
最后的效果图如下: