IT小白菜

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
iterator_to_array — 将迭代器中的元素拷贝到数组
$statement = $this->sql->prepareStatementForSqlObject($select);
    $result = iterator_to_array($statement->execute());
 
Report a bug
 说明
 
array iterator_to_array ( Traversable $iterator [, bool $use_keys ] )
将迭代器中的元素拷贝到数组。
 
4.获取最后插入的id
$lastInsertId = $result->getGeneratedValue();
5.获取get过来的值
$request = $this->getRequest()
$request->getQuery()->get('name');
6.获取<?php echo $this->url('logistics', array('action'=>'editfreight','id' => $transport['transport_id'])); ?>
url传过来的值
http://infiwiterp.com/ebay/logistics/editfreight/29
 
$id = (int)$this->params('id');
7.如果同过id或其他条件只获取一条数据
$select = $this->sql->select('ebay_freight');
$select->where(array('transport_id' => $transport_id));
 
$statement = $this->sql->prepareStatementForSqlObject($select);
$result = $statement->execute();
 
if(!$result){
throw new \Exception("Could not select Freight");
}
 
return $result->current();//返回一个数组
 
8.result
namespace Zend\Db\Adapter\Driver;
 
interface ResultInterface extends \Countable, \Iterator
{
public function buffer();
public function isQueryResult();
public function getAffectedRows();
public function getGeneratedValue();
public function getResource();
public function getFieldCount();
}
 
9.模板中foreach  中嵌套foreach,第二个foreach里参数必须转化为数组形式
 
10.use Zend\Db\Sql\Expression;
$select->columns(array(new Expression('sum(case when status = 1 then 1 else 0 end) as reply_count'),new Expression('sum(case when status = 2 then 1 else 0 end) as read_count'),new Expression("DATE_FORMAT(`reply_time`,'%Y-%m-%d') as reply_date"),'reply_user','status','reply_time'));
    $select->group(new Expression("DATE_FORMAT(`reply_time`,'%Y-%m-%d'),reply_user"));
 
11.$select->where(array("transport_id =".$transport_id, "id <>". $id))
 
12.控制器里分页处理
countarray = iterator_to_array($result);
$countarray = new Paginator(new Adapter\ArrayAdapter($countarray));
    $countarray->setItemCountPerPage($limit);
    $countarray->setCurrentPageNumber($page);
    $processUrl = new ProcessUrl($request);
 
13.分组统计
$select->where($where);
    $select->group(array(new Expression('date(shipped_time)'),'marked_user_id'))->columns(array(new Expression('count(*) as nums'),'marked_user_id',new Expression('date(shipped_time)')));
    $select->join('admin_user',$this->orderTable.'.marked_user_id = admin_user.user_id',array('user_name'),left);
posted on 2013-04-17 13:44  IT小白菜  阅读(245)  评论(0)    收藏  举报