내 Yii 프로젝트에서 페이지 매김의 기본 pageSize를 자동으로 가져 오려고하므로 페이지 매김을 사용하는 모든 위젯에서 지정할 필요가 없습니다. 하지만 Yii 소스 파일을 편집하지 않고도 페이지 매김 클래스를 전역 적으로 변경할 수있는 방법을 찾을 수 없습니다. 이것이 가능한가?Yii에서 기본 페이지 매김 속성을 변경하려면 어떻게해야합니까?
1
A
답변
1
아래 코드로 /components/WidgetFactory.php에 파일을 만드십시오.
<?php
/**
* Custom WidgetFactory class
* Provides two new events:
* - onBeforeCreateWidget
* - onAfterCreateWidget
*
* Allows for advanced global widget alteration, going a step further than CWidgetFactory's
* typical process which allows you to define default values for widgets.
*
*/
class WidgetFactory extends CWidgetFactory
{
/**
* Raised right BEFORE a widget is created.
* @param CEvent $event the event parameter
*/
public function onBeforeCreateWidget(CEvent $event)
{
$this->raiseEvent('onBeforeCreateWidget',$event);
}
/**
* Raised right AFTER a widget is created.
* @param CEvent $event the event parameter
*/
public function onAfterCreateWidget(CEvent $event)
{
$this->raiseEvent('onAfterCreateWidget',$event);
}
/**
* Creates a new widget based on the given class name and initial properties.
* @param CBaseController $owner the owner of the new widget
* @param string $className the class name of the widget. This can also be a path alias (e.g. system.web.widgets.COutputCache)
* @param array $properties the initial property values (name=>value) of the widget.
* @return CWidget the newly created widget whose properties have been initialized with the given values.
*/
public function createWidget($owner,$className,$properties=array())
{
if (! ($this->hasEventHandler('onBeforeCreateWidget') || $this->hasEventHandler('onAfterCreateWidget')))
return parent::createWidget($owner, $className, $properties);
$event=new WidgetEvent($this, $owner, $className, $properties);
if ($this->hasEventHandler('onBeforeCreateWidget'))
$this->raiseEvent('onBeforeCreateWidget', $event);
$event->widget=parent::createWidget($owner, $className, $properties);
if ($this->hasEventHandler('onAfterCreateWidget'))
$this->raiseEvent('onAfterCreateWidget', $event);
return $event->widget;
}
}
class WidgetEvent extends CEvent
{
/**
* @var CBaseController Owner of the new widget
*/
public $owner;
/**
* @var string Widget class name
*/
public $className;
/**
* @var CWidget The newly created widget
*/
public $widget;
/**
* Constructor.
* @param WidgetFactory $sender The WidgetFactory instance
* @param CBaseController $owner The owner of the new widget
* @param string $className The class name of the widget. This can also be a path alias.
* @param array $params The initial property values (name=>value) of the widget.
*/
public function __construct(WidgetFactory $sender, CBaseController $owner, $className, array $params=array())
{
parent::__construct($sender, $params);
$this->owner=$owner;
$this->className=$className;
}
}
다음과 같이 config/main.php를 수정하십시오.
return array(
// ...
'components'=>array(
// ...
'widgetFactory'=>array(
'class'=>'WidgetFactory',
'onAfterCreateWidget'=>function(WidgetEvent $event){
static $defaultPageSize=50; // YOUR_DEFAULT_PAGESIZE_HERE
$widget=$event->widget;
if ($widget instanceof CBaseListView) {
/** @var CBaseListView $widget */
if ($widget->dataProvider!==null && $widget->dataProvider->pagination!==false)
$widget->dataProvider->pagination->pageSize=$defaultPageSize;
}
},
),
// ...
),
);
설정 코드에서 위의 크기 페이지를 참조하십시오. 나는 그것이 당신의 문제를 해결할 것이라고 생각합니다.
+0
요점을 답안에 복사하고 요지로 연결하지 마십시오. 그 요점을 지우면 대답은 의미가 없습니다. – dstarh
관련 문제
- 1. Spring에서 enum의 속성을 변경하려면 어떻게해야합니까?
- 2. 기본 wordpress 갤러리 페이지 매김
- 3. Joomla getItems 기본 페이지 매김
- 4. 기본 WordPress 루프 - 페이지 매김?
- 5. WPF 프레임의 탐색 모음에서 속성을 변경하려면 어떻게해야합니까?
- 6. 기본 배경 이미지로 변경하려면 어떻게해야합니까?
- 7. Git에서 기본 디렉토리를 변경하려면 어떻게해야합니까?
- 8. Google 크롬의 인쇄 창의 기본 페이지 설정을 변경하려면 어떻게해야합니까?
- 9. Yii에서 동적으로 기본 동작을 설정하는 방법
- 10. 숨겨진 페이지 매김 요약 텍스트
- 11. 은 미나리 페이지 매김
- 12. 스택과 같은 GTK 위젯의 속성을 변경하려면 어떻게해야합니까?
- 13. Fusionchart의 데이터 세트에서 속성을 변경하려면 어떻게해야합니까?
- 14. CGI 프로그램에서 rowspan 속성을 변경하려면 어떻게해야합니까?
- 15. SQL Server 2008에서 ID 속성을 변경하려면 어떻게해야합니까?
- 16. Raphael SET에서 개별 오브젝트의 속성을 변경하려면 어떻게해야합니까?
- 17. YouTube 구독 위젯의 표시 속성을 변경하려면 어떻게해야합니까?
- 18. DataGridViewImageCoulmn의 속성을 stretchImage (pictureBox)로 변경하려면 어떻게해야합니까?
- 19. 특정 클래스에서만 링크 속성을 변경하려면 어떻게해야합니까?
- 20. 매김 페이지
- 21. Jquery를 사용하는 기본 페이지 매김 문제
- 22. Cakephp 기본 색인 작업 및 페이지 매김
- 23. 아약스에서 페이지 매김 링크를 얻으려면 어떻게해야합니까?
- 24. Yii에서 행을 삭제하려면 어떻게해야합니까?
- 25. 페이지 매김
- 26. 번호가 페이지 매김 페이지
- 27. 페이지 매김 페이지 수
- 28. 페이지 페이지 매김 jquery
- 29. div의 일반 페이지 흐름을 변경하려면 어떻게해야합니까?
- 30. Android에서 기본 셔터 음을 변경하려면 어떻게해야합니까?
http://www.yiiframework.com/forum/index.php/topic/39265-widget-pagination-global-solution/ 필요한 것이 있습니다! – secretlm