刚接触了两个礼拜的tp框架,结果项目要使用zend框架,虽说都是php框架,但还是有不少区别。这个贴子主要收集zend中需要注意的地方
一个zend的框架
首先zend中模型对应的是models
控制器对应的controllers
template则对应的模版视图
控制器controllers文件命名需要注意的是
写道
在admin分组下的一个IndexController.php文件,对应的是一个控制器。
控制器声明很有意思
class Admin_IndexController extends PublicController
实际上是 分组_控制器 这样命名一个class
控制器声明很有意思
class Admin_IndexController extends PublicController
实际上是 分组_控制器 这样命名一个class
模型较类似,遇到新问题再说。
视图,控制器向视图传值的方式和tp以及smarty不一样。
控制器中
$this->view->id = 5;
视图中
<?php= $this->id;?>
视图中值只能在php模块部分取出,再使用js对页面中其他组件进行赋值。
这里 = 的作用 就是echo的简写
Zend下连表查询
$sql = $this->_db->select()->from($this->_name." as a")
->join("amd_admin as b", 'a.admin_id = b.id', array('b.username as a.admin_id'))
->where("a.id='$id'");
$row = $this->_db->fetchRow($sql);
关键的地方在于join
写道
Zend_Db_Select.join(array|string|Zend_Db_Expr $name, string $cond, array|string $cols, string $schema)
Adds a JOIN table and columns to the query.
Parameters:
array|string|Zend_Db_Expr $name The table name. 加入连表名
string $cond Join on this condition. 连表条件
array|string $cols The columns to select from the joined table. 从连表中查询的字段
string $schema The database name to specify, if any. 数据库名
Returns:
Zend_Db_Select This Zend_Db_Select object.
Adds a JOIN table and columns to the query.
Parameters:
array|string|Zend_Db_Expr $name The table name. 加入连表名
string $cond Join on this condition. 连表条件
array|string $cols The columns to select from the joined table. 从连表中查询的字段
string $schema The database name to specify, if any. 数据库名
Returns:
Zend_Db_Select This Zend_Db_Select object.