當前位置: 首頁>>代碼示例>>PHP>>正文


PHP GridField::setDisplayFields方法代碼示例

本文整理匯總了PHP中GridField::setDisplayFields方法的典型用法代碼示例。如果您正苦於以下問題:PHP GridField::setDisplayFields方法的具體用法?PHP GridField::setDisplayFields怎麽用?PHP GridField::setDisplayFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GridField的用法示例。


在下文中一共展示了GridField::setDisplayFields方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: ListViewForm

	public function ListViewForm(){
		$params = $this->request->requestVar('q');
		$list = $this->getList($params, $this->request->requestVar('ParentID'));
		$gridFieldConfig = GridFieldConfig::create()->addComponents(
			new GridFieldSortableHeader(),
			new GridFieldDataColumns(),
			new GridFieldPaginator(15)
		);
		$gridField = new GridField('Page','Pages', $list, $gridFieldConfig);
		$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');

		// Don't allow navigating into children nodes on filtered lists
		if($params){
			$gridField->setDisplayFields(array(
				'getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'),
				'Created' => _t('SiteTree.CREATED', 'Date Created'),
				'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'),
			));
		}else{
			$columns->setDisplayFields(array(
				'listChildrenLink' => "",
				'getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'),
				'Created' => _t('SiteTree.CREATED', 'Date Created'),
				'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'),
			));
		}
		
		$columns->setFieldCasting(array(
			'Created' => 'Date->Ago',
			'LastEdited' => 'Date->Ago',
		));

		$controller = $this;
		$columns->setFieldFormatting(array(
			'listChildrenLink' => function(&$item) use($controller) {
				$num = $item->numChildren();
				if($num) {
					return sprintf(
						'<a class="cms-panel-link list-children-link" data-pjax="ListViewForm" data-target-panel="#Form_ListViewForm" href="%s?ParentID=%d&view=list">%s</a>',
						$controller->Link(),
						$item->ID,
						$num
					);	
				}
			},
			'getTreeTitle' => '<a class=\"cms-panel-link\" href=\"' . 
				singleton('CMSPageEditController')->Link('show') . '/$ID\">$value</a>'
		));
		
		$listview = new Form(
			$this,
			'ListViewForm',
			new FieldList($gridField),
			new FieldList()
		);

		$this->extend('updateListView', $listview);
		
		$listview->disableSecurityToken();
		return $listview;
	}
開發者ID:redema,項目名稱:silverstripe-cms,代碼行數:61,代碼來源:CMSMain.php


注:本文中的GridField::setDisplayFields方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。