本文教大家如何在typo3插件开发中去使用flexform
1.  我们首先在插件的根目录创建一个叫new_flexform_p1.xml的文件,代码如下:
这个一个flexform的基本框架代码,结构是如何组织的,大家看我在代码里的注释。

<T3DataStructure>
<meta>
  <langDisable>1</langDisable>
</meta>
<sheets> //我们创建的内容包在sheets里面
<sDEF> // sDEF是第一个tag ,也是默认的tag,tag名叫General,等下在截图中可以看到.
<ROOT>
   <TCEforms>
     <sheetTitle>LLL:EXT:sampleflex/locallang_db.php:tt_content.pi_flexform.sheet_general</sheetTitle> // Tag的label名配在language.xml
  </TCEforms>
  <type>array</type>
  <el> // 这里是你要配制的flexform的项目.
   <What_to_dispaly> //比如这里我配了一个叫what_to_display的项.
    <TCEforms>

     <label>LLL:EXT:lang/locallang_general.php:LGL.recursive</label>
     <config>
     <type>select</type>
      <items type="array">

       <numIndex index="0" type="array">
         <numIndex index="0">Search List</numIndex> // 这是显示的文字
         <numIndex index="1">list</numIndex> // 这里是实际获取到的值
       </numIndex>
       <numIndex index="1" type="array">

          <numIndex index="0">Single</numIndex>
          <numIndex index="1">single</numIndex> 
       </numIndex>
       </items>
      <minitems>0</minitems> 
      <maxitems>1</maxitems>
      <size>1</size>
     </config>
    </TCEforms>
  </What_to_dispaly>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
2.在插件中引入flexfrom,我们要修改的文件是ext_tables.php这个文件,添加以下两行:
$TCA['tt_content']['types']['list']['subtypes_addlist'][$_EXTKEY.'_pi1']='pi_flexform';
t3lib_extMgm::addPiFlexFormValue($_EXTKEY.'_pi1', 'FILE:EXT:'.$_EXTKEY.'/new_flexform_p1.xml);

3.在pi文件中我们就个去获取我们在flexform配的项目的值了.
$what_to_display=$this->pi_getFFvalue($this->cObj->data['pi_flexform'],'what_to_display','sDEF'); //sDEF是默认的tag可以不写,但是其他的tag必须的写.

这样$what_to_display的值为 list or single.4.看效果图:


若转载请注明出处: TYPO3中文网
本文地址: http://www.51typo3.cn/typo3/74.html