2013-05-03 06:41:06 +00:00
|
|
|
|
<?php
|
2013-10-28 14:54:21 +00:00
|
|
|
|
class view extends \Zend_Controller_Plugin_Abstract
|
2013-05-03 06:41:06 +00:00
|
|
|
|
{
|
|
|
|
|
private $db; //传入PDO对象.
|
|
|
|
|
private $product = 0; //产品环境
|
|
|
|
|
|
|
|
|
|
function __construct($db='')
|
|
|
|
|
{
|
|
|
|
|
$this->db = $db;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 14:54:21 +00:00
|
|
|
|
static function addPaginator($data,$ctl,\Zend_Controller_Request_Abstract $request = NULL,$limit = 10)
|
2013-05-03 06:41:06 +00:00
|
|
|
|
{
|
2013-06-08 09:51:44 +00:00
|
|
|
|
if(empty($request))
|
|
|
|
|
{
|
|
|
|
|
$request = $ctl->getRequest();
|
|
|
|
|
$page = $request->getParam('page');
|
|
|
|
|
$view = $ctl->view;
|
|
|
|
|
}else{
|
|
|
|
|
$page = $request->getParam('page');
|
|
|
|
|
$view = $ctl;
|
|
|
|
|
}
|
2013-05-03 06:41:06 +00:00
|
|
|
|
|
2013-10-28 14:54:21 +00:00
|
|
|
|
$paginator = \Zend_Paginator::factory($data);
|
2013-05-03 06:41:06 +00:00
|
|
|
|
$paginator->setCurrentPageNumber($page);
|
2013-06-08 09:51:44 +00:00
|
|
|
|
$paginator->setItemCountPerPage($limit);
|
|
|
|
|
$paginator->setView($view);
|
2013-10-28 14:54:21 +00:00
|
|
|
|
\Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
|
2013-06-08 09:51:44 +00:00
|
|
|
|
$view->paginator = $paginator;
|
2013-05-03 06:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static function Msg($type,$content,$url=''){
|
|
|
|
|
$html = '<div class="alert '.$type.'">'."\r\n";
|
|
|
|
|
$html.= '<a data-dismiss="alert" class="close">×</a>'."\r\n";
|
|
|
|
|
$html.= $content."\r\n";
|
|
|
|
|
$html.= '</div>'."\r\n";
|
|
|
|
|
if(!empty($url))
|
|
|
|
|
{
|
|
|
|
|
if($url == -1){
|
|
|
|
|
$html.= '<script language="javascript">setTimeout("window.history.back(-1);",3000);</script>'."\r\n";
|
2013-06-08 09:51:44 +00:00
|
|
|
|
}elseif($url == 0){
|
2013-06-06 13:36:25 +00:00
|
|
|
|
|
2013-05-03 06:41:06 +00:00
|
|
|
|
}else{
|
|
|
|
|
$html.= '<script language="javascript">setTimeout("self.location=\''.$url.'\'",3000);</script>'."\r\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $html;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-09 03:53:27 +00:00
|
|
|
|
static function Error($content,$type='',$url=''){
|
2013-05-03 06:41:06 +00:00
|
|
|
|
if(empty($type))
|
|
|
|
|
{
|
|
|
|
|
$AlertType = "alert-error";
|
|
|
|
|
}else{
|
|
|
|
|
$AlertType = $type;
|
|
|
|
|
}
|
|
|
|
|
$html = '<div class="alert alert-block fade in '.$AlertType.'" id="Alert-error-box">'."\r\n";
|
|
|
|
|
$html.= '<a class="close" data-dismiss="alert" href="#">×</a>'."\r\n";
|
|
|
|
|
if(!is_array($content)) {
|
|
|
|
|
$html.= '<h4 class="alert-heading">'.$content.'</h4>'."\r\n";
|
|
|
|
|
}else{
|
|
|
|
|
$html.= '<ul>'."\r\n";
|
|
|
|
|
foreach($content as $v) {
|
|
|
|
|
$html.='<li>'.$v.'</li>'."\r\n";
|
|
|
|
|
}
|
|
|
|
|
$html.= '</ul>'."\r\n";
|
|
|
|
|
}
|
|
|
|
|
$html.= '</div>'."\r\n";
|
|
|
|
|
return $html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static function User($param){
|
2013-10-28 14:54:21 +00:00
|
|
|
|
$auth = \Zend_Auth::getInstance();
|
2013-05-03 06:41:06 +00:00
|
|
|
|
if($auth->hasIdentity())
|
|
|
|
|
{
|
|
|
|
|
$user = $auth->getIdentity();
|
|
|
|
|
return $user->$param;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static function Dump($data,$exit = true){
|
|
|
|
|
echo "<pre>";
|
|
|
|
|
var_dump($data);
|
|
|
|
|
echo "</pre>";
|
|
|
|
|
if($exit)
|
|
|
|
|
{
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 14:54:21 +00:00
|
|
|
|
static function Post(\Zend_Controller_Action $ctl,$msg,$url=""){
|
2013-05-03 06:41:06 +00:00
|
|
|
|
|
|
|
|
|
if(empty($msg))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-05-21 09:37:33 +00:00
|
|
|
|
if(!is_array($msg))
|
2013-05-03 06:41:06 +00:00
|
|
|
|
{
|
2013-05-21 09:37:33 +00:00
|
|
|
|
$msg = array('content'=>$msg,'url'=>$url);
|
2013-05-03 06:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 14:54:21 +00:00
|
|
|
|
$helper = new \Zend_Controller_Action_HelperBroker($ctl);
|
2013-05-21 09:37:33 +00:00
|
|
|
|
$helper->layout->setLayout('layout');
|
2013-05-03 06:41:06 +00:00
|
|
|
|
$helper->viewRenderer->setNoRender();
|
|
|
|
|
echo $ctl->view->partial('post-message.phtml', $msg);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-10-28 14:54:21 +00:00
|
|
|
|
|
|
|
|
|
static function getHostLink()
|
|
|
|
|
{
|
|
|
|
|
$protocol = "http";
|
|
|
|
|
if(strpos(strtolower($_SERVER['SERVER_PROTOCOL']),"https"))
|
|
|
|
|
{
|
|
|
|
|
$protocol = "https";
|
|
|
|
|
}
|
|
|
|
|
return $protocol."://".$_SERVER['SERVER_NAME'];
|
|
|
|
|
}
|
2013-04-22 10:18:48 +00:00
|
|
|
|
}
|