当前位置: 首页>>代码示例>>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;未经允许,请勿转载。