【bob体育平台】Yii使用CLinkPager分页实例详解_php实例_脚本之家

2020-02-08 13:36栏目:编程
TAG:

正文实例呈报了yii去掉必填项中星号的法子。共享给我们供大家参谋,具体如下:

本文重要教师了YII中接纳CLinkPager分页的章程,这里我们使用物件的款式来定义分页:

什么去掉必填项里的星号呢?

率先在components中自定义LinkPager,并世襲CLinkPager

public function labelEx($model,$attribute,$htmlOptions=array{ return CHtml::activeLabelEx($model,$attribute,$htmlOptions);}public static function activeLabelEx($model,$attribute,$htmlOptions=array{ $realAttribute=$attribute; self::resolveName; // strip off square brackets if any $htmlOptions['required']=$model->isAttributeRequired; return self::activeLabel($model,$realAttribute,$htmlOptions);}
>'. */ public $totalRowLabel; /** * Creates the page buttons. * @return array a list of page buttons . */ protected function createPageButtons() { $this->maxButtonCount=8; $this->firstPageLabel="首页"; $this->lastPageLabel='末页'; $this->nextPageLabel='下一页'; $this->prevPageLabel='上一页'; $this->header=""; if(($pageCount=$this->getPageCount; list=$this->getPageRange(); $currentPage=$this->getCurrentPage; // currentPage is calculated in getPageRange; // first page $buttons[]=$this->createPageButton($this->firstPageLabel,0,self::CSS_FIRST_PAGE,$currentPage<=0,false); // prev page if(<0) $page=0; $buttons[]=$this->createPageButton($this->prevPageLabel,$page,self::CSS_PREVIOUS_PAGE,$currentPage<=0,false); // internal pages for($i=$beginPage;$i<=$endPage;++$i) $buttons[]=$this->createPageButton($i+1,$i,self::CSS_INTERNAL_PAGE,false,$i==$currentPage); // next page if(>=$pageCount-1) $page=$pageCount-1; $buttons[]=$this->createPageButton($this->nextPageLabel,$page,self::CSS_NEXT_PAGE,$currentPage>=$pageCount-1,false); // last page $buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,self::CSS_LAST_PAGE,$currentPage>=$pageCount-1,false); // 页数统计 $buttons[]=$this->createTotalButton."/{$pageCount}",self::CSS_TOTAL_PAGE,false,false); // 条数统计 $buttons[]=$this->createTotalButton("共{$this->getItemCount()}条",self::CSS_TOTAL_ROW,false,false); return $buttons; } protected function createTotalButton($label,$class,$hidden,$selected) { if $class.=' '.($hidden ? self::CSS_HIDDEN_PAGE : self::CSS_SELECTED_PAGE); return '

当属性是必填的时候,它将渲染额外的CSS类个暗记。特别的,它调用CModel::isAttributeRequired来决定属性是或不是为必填的。借使是,它将助长三个CSS类CHtml::requiredCss (public static $requiredCss='required';)到标签上,用CHtml::beforeRequiredLabel(public static $beforeRequiredLabel='';)和CHtml::afterRequiredLabel (public static $afterRequiredLabel='*';)来点缀标签。

'.CHtml::label.'

public function isAttributeRequired{ foreach($this->getValidators as $validator) { if($validator instanceof CRequiredValidator) return true; } return false;}

'; } /** * Registers the needed client scripts . */ public function registerClientScript() { if($this->cssFile!==false) self::registerCssFile; } /** * Registers the needed CSS file. * @param string $url the CSS URL. If null, a default CSS URL will be used. */ public static function registerCssFile { if $url=CHtml::asset(Yii::getPathOfAlias('application.components.views.LinkPager.pager').'.css'); Yii::app->registerCssFile; }}

之所以要去掉星号 可能换来其余能够再view中直接重新定义CHtml::requiredCss、CHtml::beforeRequiredLabel、CHtml::afterRequiredLabel就可以

定义CSS样式

版权声明:本文由bob体育app发布于编程,转载请注明出处:【bob体育平台】Yii使用CLinkPager分页实例详解_php实例_脚本之家