Bitrixã®ãããã¯ã«é¢ããç§ããã®å¥ã®èªæ®ºèšäºã¯ãä»åã¯habrabsocietyãããå¯å€§ã«ãªãããšãé¡ã£ãŠããŸã å®éã«ã¯ãã³ãŒããã¹ããŒã ãããªããŒãªãã§ãã¹ãŠãããã«ããããã¹ãŠãå ¬å¹³ã§ãã
ãã®èšäºã§ã¯ãBitrixFrameworkã®ä»£æ¿æ¡ãæ€èšããŸããããã¯ãéçºè ã®äœæ¥ã楜ã«ããBitrix CMSã®éçºã«äœããã®åœ¢ã§æ£ããæ¹åã«åœ±é¿ãäžããããã«èšèšãããŠããŸãã
å«ããªäººãžã®å¯Ÿå¿ïŒéåžžã®æ¹å€ãšãã«ã«ããžã®ãããã¯ã«é¢ããã³ã¡ã³ããæžãå Žåãå人çã«éä¿¡ããŸã;-)ã çš®ã®Volfychaãå éšã®ãã¹ãŠãèå³æ·±ã...
ãŸãããã¹ãŠã®ãiãã«ããããä»ããŸããã
以äžã«æžãããŠããããšã¯ãã¹ãŠç§ã®å人çãªæèŠã§ãããã¹ãªããã«èœã¡çããŠæããããšãã§ããŸãããç§ã¯æ£ãããšç¢ºä¿¡ããŠããŸãïŒ
- ãBitrixã«ã¯100äžè¡ã®ããããšããããŸãã -ã¯ããééããããŸããã å šäœã®åé¡ã¯ãBitrixãäžäœäºææ§ããµããŒãããŠããããšã§ãïŒããŒãžã§ã³12.0ãã16.5ã«æŽæ°ãããšããã¹ãŠãæ£åžžã«æ©èœããã¯ãã§ãïŒã ãªã圌ãããããããã®ããç§ã«ã¯ããããŸããïŒç§ã«ã¯èª°ãç¥ããªãããã§ãïŒã æšæºã³ã³ããŒãã³ãã®ãœãŒã¹ïŒæ å ±ãããã¯èŠçŽ ã衚瀺ããããã®2Kè¡ã®ã³ãŒã-ç©äºã®é åºïŒã«ã€ããŠè©±ããšãé£äžã¯ãšã³ããŠãŒã¶ãŒã䜿ããããããããšã決å®ããæ³å®ã§ãããã¹ãŠã®ãã®ãæäŸããŸããïŒããã¯äºå®ã§ã¯ãããŸããïŒãå¿ èŠãªãšãã«ã ããŠãè¿œãã€ãããã«ãæè¿ã®ã»ãããŒã§ãBitrixéçºè ã¯PSRã«å¯Ÿããæ 床ãçºè¡šããŸããïŒããŸãããã®PSRãšã¯äœããç§ã¯ãããèªãã§ãäœäººãã®ç·ãéãŸã£ãŠãŽããæžããŸãããïŒæ£ç¢ºãªåŒçšã§ã¯ãããŸããïŒã ãããã£ãŠãã³ãŒãã¯åžžã«èããããŸãã
- ãBitrixã«ã¯ã²ã©ãæ§é ããããŸãã -ããã§ã¯ãããŸããã Bitrixã¯ãã¡ã€ã«ããŒã¹ã§ãããMVCã®ç解ã¯äžè¬ã«åãå ¥ããããŠãããã®ãšã¯ç°ãªããå€ãã®å ŽåããMVCã§ã¯ãªãã=ããã©ãŒãã©ãŒãšã¯äœãã®æ§é ãã§ãã ãããã£ãŠãããã¯éåžžã«ç©è°ãããããç©è°ãéžãåé¡ã§ãã ãããŠãããªãã¯Bitrixæ§é ã§çããããšãã§ããŸãã
- ãBitrixFrameworkã¯æ±ºããŠçºå±ããªãã -ãããç§ã®æèŠã§ãããããã«çç±ããããŸãããªãªãŒã¹ããšã«ãBitrixã¯ãShopãã¢ãžã¥ãŒã«ã®ã¿ããã¡ã€ãã©ã€ãºããããã€ãã®å€æŽãè¡ããŸããããããã¯ãã¹ãŠã¹ãã¢ã察象ãšããŠããŸãã 圌ãã¯ççŽã«èšã£ãŠæ®ããæ°ã«ããŸããã BFã®éçºã¯ãäžäœäºææ§ãæŸæ£ããShopã¢ãžã¥ãŒã«ä»¥äžã®ãã®ãæ±ãããã«ãªã£ããšãã«å§ãŸããŸãã
ãžã£ã¬ãŒããŒãã«äŒããïŒ
確ãã«å€ãã®äººããã®ãã£ã©ã¯ã¿ãŒã«ç²ŸéããŠããŸãïŒDotaããã§ã¯ãªããMarvelããïŒã圌ã¯ããããããªããã å°ãåããªååã¯ãå®éããã®ãããžã§ã¯ãã®æ¬è³ªãåæ ããŠããŸããããã¯ãBitrixã®éçºæ¹æ³ãå°å ¥ãããã€ãããŒã·ã§ã³ãã©ã€ãã©ãªã®åç¶ãšç¹æ ã«ãŸã£ããé¢ä¿ãããŸããã
Bitrixã¯ãŠãŒã¶ãŒã察象ãšããŠããŸãã Juggernautã¯éçºè åãã§ãã
ãªããããå¿ èŠãªã®ã§ããïŒ
å¿ èŠã ããïŒ å®éã«ã¯ãã¹ãŠãéåžžã«è«ççã§ãïŒ
- Bitrixã¯æ°ããã«ãŒãã«ãéçºããŠããŸãïŒè¯ãïŒãã圌ãã¯ãŸã£ããææžåããããªãïŒæªãïŒ;
- Bitrixã¯æ°ããæ©èœãéçºããŠããŸãïŒè¯ãïŒããã¹ãã¢å°çšã§ãïŒæªãïŒã
- Bitrixã¯æ°ããã³ã³ããŒãã³ããéçºããŠããŸãïŒè¯ãïŒããç®ããã®ã³ãŒãã®è¡ããïŒæªãïŒ;
- Bitrixã¯ãæ°ãããæè¡ãè€åãµã€ããã®ç¹èš±ãååŸããŸããïŒæªãïŒã
ããŒãžã§ã³14ããã¯ãããŒãžã§ã³14ã®å€ãã«ãŒãã«ã®ãµããŒããçµäºããæ°ããããããã顧客ãžã®é æ ®ãã«éç¹ã眮ãå¿ èŠããããŸããã ã§ãããã ããã¯ãYii2ãYii1ããµããŒãããŠçµã¿åãããå Žåãåãã§ãã
Bitrixã¯é²æ©ãéããŠããªããããã³ãã¥ããã£ã¯ïŒæ³£ãèšãIdeaãµãŒãã¹ãžã®æžã蟌ã¿ãæšæºã³ã³ããŒãã³ãã䜿çšãããããã®ä»£ããã«ïŒãããè¡ããŸãã
Scããããããªãã¯ã¹ãä»ããžã£ã¬ãŒããŒãã®ã¬ãã¥ãŒãå§ããããšãã§ããŸãã 次ã«ãã©ã€ãã©ãªã®æ§æéšåã®æŠèŠãšãã®äœ¿çšæ¹æ³ã®ç°¡åãªèª¬æãéå§ããŸãã
ã³ã³ããŒãã³ã
ã³ã³ããŒãã³ãã¯ãBitrix Webãµã€ãã®æ§ç¯å ãšãªãããªãã¯ã§ãã ã³ã³ããŒãã³ãã¯æ¡ä»¶ä»ãã§2ã€ã®ã«ããŽãªã«åé¡ãããŸãïŒãŠã£ãžã§ãããšã«ãŒã¿ãŒïŒBitrixè¡šèšã§ã¯ãéåžžããšãè€éãïŒã
ãŠã£ãžã§ãã
ãŠã£ãžã§ããã¯ãæããªããšã«1ã€ã®åºæ¬çãªã¿ã¹ã¯ãå®è¡ããïŒãã©ãŒã ããªã¹ããæ å ±ã衚瀺ããïŒã³ã³ããŒãã³ãã§ãã ãŠã£ãžã§ããã¯å ¥åãåãåããäœããã®æ¹æ³ã§ãããå€æããŸãã 圌ã¯ä»ã«äœãããã¹ãã§ã¯ãããŸããã ãŠã£ãžã§ããã¯ã«ãŒãã£ã³ã°ãå¶åŸ¡ããŸãããã䜿çšã§ããŸãã
ã³ã³ããŒãã³ãå®è¡ã®ããã©ã«ãã®é åºïŒ
é çªã«ïŒ
- init-åæããŒã¿ãåæåããŸãã å ¥åãã©ã¡ãŒã¿ãŒïŒ$ arParamsïŒãã¯ã©ã¹ããããã£ã«å€æããŸãã
- onBefore-ã¢ã¯ã·ã§ã³ã®å¯èœæ§ããã§ãã¯ããŸãã
- isCachedTemplate-ãã£ãã·ã¥ãããã³ããŒããããã©ããã決å®ãããã©ã°ã ååšããå Žåã¯ãã£ãã·ã¥ããŒã¿ã衚瀺ããååšããªãå Žåã¯ãã£ãã·ã¥ããŒã¿ã圢æããŸãïŒã³ãŒãã§ã¯èŠãç®ãå°ãç°ãªããŸãããå³ã§ã¯ç°¡åã«ããããã«ããã瀺ããŠããŸãïŒã
- initResult-ãã¬ãŒã³ããŒã·ã§ã³çšã®ããŒã¿ãçæïŒ$ arResultïŒ;
- run-ãŠã£ãžã§ãããçŽæ¥å®è¡ããæ©èœã ããŒã¿ïŒ$ arResultïŒã§äœãããå¿ èŠããããã決å®ããŸãã
- onBeforeRender-ãã³ãã¬ãŒãåºåã®å¯èœæ§ããã§ãã¯ããå€æãå®è¡ããŸãïŒresult_modifier.phpãšåæ§ã§ãããåæ§ã«äœ¿çšã§ããŸãïŒã
- render-ã³ã³ããŒãã³ããã³ãã¬ãŒãã®çŽæ¥åºåã
- onAfter-ãŠã£ãžã§ãããå®è¡ããåŸã®ã¢ã¯ã·ã§ã³ã®å®è¡ïŒcomponent_epilog.phpã®ã¢ããã°ïŒã
ã»ãšãã©ã®å Žåãåã«initResultã¡ãœããããªãŒããŒã©ã€ãããã³ã³ããŒãã³ããã³ãã¬ãŒããã¹ããŒããŸãã
以äžã¯ãinfoblockèŠçŽ ã®ãªã¹ãã衚瀺ããã³ã³ããŒãã³ãã¯ã©ã¹ïŒclass.phpïŒã®äŸã§ãã å ¥åã§ããã©ã¡ãŒã¿ãŒã®é åïŒ$ paramsïŒãåãåããŸããããã¯ãããŒã¿ã®ãã£ã«ã¿ãŒåŠçãšäžŠã¹æ¿ãã«äœ¿çšãããŸãã
ã³ãŒã
<?php namespace Widget\Iblock\Element\List_; use Jugger\Db\Orm\Ib\IblockElement; use Jugger\Component\WidgetComponent; class Component extends WidgetComponent { /* * 'init', * $arParams , * : $this->params = $arParams['params'] */ public $params = []; /* * , * , */ protected function init() { parent::init(); $this->isCachingTemplate = true; } /* * */ protected function initResult() { $this->arResult['elements'] = IblockElement::getList($this->params); } }
ã«ãŒã¿ãŒ
ã«ãŒã¿ãŒã®ã¿ã¹ã¯ã¯ããŠã£ãžã§ãããäžç·ã«åéããããšã§ãã ã«ãŒã¿ãŒ-ãŠãŒã¶ãŒèŠæ±ïŒREQUEST_URIïŒã«åºã¥ããŠã察å¿ããã¢ã¯ã·ã§ã³ãåŒã³åºãã³ã³ãããŒã©ãŒã§ãã ã¢ã¯ã·ã§ã³ã¯ãæ å ±ãå«ãããŒãžïŒãŠã£ãžã§ãããå«ãïŒããäœããã®ããžãã¯ãå«ãããšãã§ããŸãã
ã³ã³ããŒãã³ãå®è¡ã®ããã©ã«ãã®é åºïŒ
é çªã«ïŒ
- init-åæããŒã¿ãåæåããŸãã å ¥åãã©ã¡ãŒã¿ãŒïŒ$ arParamsïŒãã¯ã©ã¹ããããã£ã«å€æããŸãã
- initUrlManager - UrlManagerããšã€ãªã¢ã¹ã§åããŸã ãã®ã¢ã¯ã·ã§ã³ã¯ãã¢ã¯ã·ã§ã³ã«ããã«ãŒãã£ã³ã°ãšURLã¢ãã¬ã¹ã®ãããªãçæãå®è¡ããããã«å¿ èŠã§ãã
- parseRequest -UrlManagerãªã¯ãšã¹ãã解æãããŠãŒã¶ãŒããªã¯ãšã¹ãããã¢ã¯ã·ã§ã³ã決å®ããŸãã
- existBeforeAction-å人ã®onBeforeãã³ãã©ãŒã®ååšã確èªããŸãã ãindexãã®ã¢ã¯ã·ã§ã³ãããããonBeforeIndexãã®ã¡ãœãããããå ŽåããããåŒã³åºãããŸãããã以å€ã®å Žåã¯ãäžè¬çãªãonBeforeããåŒã³åºãããŸãã
- onBefore-ã¢ã¯ã·ã§ã³ã®å¯èœæ§ããã§ãã¯ããŸãã
- run-ã³ã³ããŒãã³ãã®çŽæ¥å®è¡ã®æ©èœã ããŒã¿ïŒ$ arResultïŒã§äœãããå¿ èŠããããã決å®ããŸãã
- existMethodAction-ã¢ã¯ã·ã§ã³ãã³ãã©ãŒã®ååšã確èªããŸãã ã¢ã¯ã·ã§ã³ 'index'ãèŠæ±ãããã¡ãœãã 'actionIndex'ãããå Žåããã®ã¡ãœãããåŒã³åºãããŸããããã§ãªãå Žåãã«ãŒã¿ãŒã¯ 'index'ãšããååã®ãã¥ãŒã衚瀺ããããšããŸãã
- onBeforeRender-ãã³ãã¬ãŒãåºåã®å¯èœæ§ããã§ãã¯ããå€æãå®è¡ããŸãïŒã¢ã¯ã·ã§ã³åã¯ãã©ã¡ãŒã¿ãŒã§æž¡ããããããå人ãã§ãã¯ãæ§æã§ããŸãïŒã
- render-ã³ã³ããŒãã³ããã³ãã¬ãŒãã®çŽæ¥åºåã
- onAfter-ãŠã£ãžã§ãããå®è¡ããåŸã®ã¢ã¯ã·ã§ã³ã®å®è¡ïŒcomponent_epilog.phpã®ã¢ããã°ïŒã ãonBeforeãã¡ãœããã§ãåæ§ã«æ©èœããŸãããindexãã¢ã¯ã·ã§ã³ã«ãonAfterIndexãã¡ãœãããããå Žåã¯åŒã³åºããããã以å€ã®å Žåã¯æ±çšã®ãonAfterããåŒã³åºãããŸãã
以äžã¯ããã£ã¬ã¯ããªãå®è£ ããã³ã³ããŒãã³ãã®äŸã§ãã
- ã¢ã€ãã ã®ãªã¹ã
- ã»ã¯ã·ã§ã³ã®ãªã¹ã
- 詳现ãªã¢ã€ãã ã«ãŒãã
ã³ãŒã
<?php namespace Widget\Iblock\Element\Catalog; use Jugger\Db\Orm\Ib\IblockElement; use Jugger\Db\Orm\Ib\IblockSection; use Jugger\Component\RouteComponent; class Component extends RouteComponent { /* * ID , */ public $iblockId; /* * , * , 'aliases' */ protected function getAliases() { return [ "sectionList" => "index.php", "elementList" => "#SECTION_CODE#/", "elementView" => "#SECTION_CODE#/#ELEMENT_CODE#/" ]; } /* * , */ protected function onBefore($action) { if (!$this->iblockId) { throw new \Exception(" 'iblockId' ". get_called_class()); } return parent::onBefore($action); } /* * */ protected function getSection($sectionCode) { return IblockSection::getRow([ "filter" => [ "IBLOCK_ID" => $this->iblockId, "CODE" => $sectionCode ], ]); } /** * */ public function actionSectionList() { $sectionList = IblockSection::getListByField( "=IBLOCK_ID", $this->iblockId, [ "order" => ["SORT" => "ASC"] ] ); $this->arResult['sectionList'] = $sectionList; $this->render('list'); } /** * * $sectionCode URL */ public function actionElementList($sectionCode) { $section = $this->getSection($sectionCode); if (!$section) { $this->error404(); } // $this->arResult['section'] = $section; $this->arResult['elementList'] = $section->getElements(); $this->render('section'); } /** * * , 'aliases' */ public function actionElementView($sectionCode, $elementCode) { $section = $this->getSection($sectionCode); if (!$section) { $this->error404(); } // $element = IblockElement::getRow([ "filter" => [ "IBLOCK_ID" => $this->iblockId, "IBLOCK_SECTION_ID" => $section->ID, "CODE" => $elementCode, ], ]); if (!$element) { $this->error404(); } $this->arResult['element'] = $element; $this->arResult['section'] = $section; $this->render('view'); } }
ã¯ã©ã¹ã®èªåããŒã
ããã¯éåžžã«å¿ èŠãªããšã§ããããšã¯ãã§ã«æããã§ããããããã®åé¡ã«ã€ããŠã¯ããŸã話ããªãã§ãããã
Juggernautã«ãã£ãŠå®è£ ããããšããïŒ
ãlibããã©ã«ããŒã§ã¯ã次ã®æ§é ã確èªããå¿ èŠããããŸããã¯ã©ã¹ãã¡ã€ã«ã®ååã¯ãæ¡åŒµåãšäžäœåå空éãå«ãŸããåå空éåãšåãã§ãã ããšãã°ãã¯ã©ã¹ãIblock \ Property \ Tableãã¯ããã¡ã€ã«ã... / modules / Iblock / lib / Property / Table.phpãã«å¯Ÿå¿ããŸãã
ãincludeModuleããåŒã³åºãå¿ èŠããªããªããŸãã å¿ èŠã«å¿ããŠããã¹ãŠã®ã¯ã©ã¹ãå¿ èŠãªãã£ã¬ã¯ããªããèªåçã«ããŒããããŸãã
ã¢ãžã¥ãŒã«ã®ãã£ã¬ã¯ããªãåå空éã®ååãšç°ãªãå ŽåããŸãã¯ãã®ä»ã®ç¶æ³ã§ã¯ãåå空éãšãã£ã¬ã¯ããªã®å¯Ÿå¿ãæåã§èšå®ã§ããŸãã
// "Jugger\D7\Iblock" "./lib/D7/Iblock.php" â \Jugger\Psr\Psr4\Autoloader::addNamespace('Jugger', __DIR__.'/lib'); // "Jugger\D7\Iblock" "./classes/Iblock.php" \Jugger\Psr\Psr4\Autoloader::addNamespace('Jugger\D7', __DIR__.'/classes');
Bitrixã«ããªãŒãããŒãããããŸããããã¹ã®åœ¢ææ¹æ³ãå°ãç°ãªããŸãã
ã¯ã©ã¹ãOlof \ Catalog \ Tools \ Fileãã¯ã/Olof.Catalog/lib/Tools/File.phpããšç¿»èš³ãããŸãã
ã¯ã©ã¹ãOlof \ Catalogããå¿ èŠãªå Žåã¯ããã¿ãŸãããæåã§ãã®ååšã瀺ããŸãïŒä»¥äžãåç §ïŒã ã¢ãžã¥ãŒã«ãã£ã¬ã¯ããªã«ã¯ãåºåãæåããããå¿ èŠã§ãããã以å€ã®å Žåã¯ããã©ã¬ã¹ãå ãæ©ããŸãã ãã£ã¬ã¯ã㪠"olof.catalog.iblock"ã®å 容-ééã£ãŠããŸãã
Bitrixã®çŽ³å£«ã¯å®éã«éåžžã®ããšãããŸããã圌ãã¯ã¢ãžã¥ãŒã«åã§ãã³ããŒãæå®ããã®ãé¢åãã¿ãŸããããããã¯ãã£ã¬ã¯ããªã«ååãä»ããããã®äœåãªæ¡ä»¶ã ãšæããŸãã
èªåããŒãã¯ãæ¥å°ŸèŸãåé€ããŠãelement.phpããã¡ã€ã«ã«å€æããããšã«ããããElementTableãã¿ã€ãã®ã¯ã©ã¹ã«æé»çã«å¿çããŸãã å®éããã®ãããTableãšããã¯ã©ã¹ãäœæããããšã¯ã§ããŸããã
ãŸããçŸåšæ¥ç¶ãããŠããªãã¢ãžã¥ãŒã«ïŒincludeModuleïŒããã¯ã©ã¹ãããŒãããããšã¯ã§ããŸããã
Bitrixãªãã·ã§ã³ã®äŸãèããŠã¿ãŸããããã¢ãžã¥ãŒã«ãolof.iblockããšå¯Ÿå¿ããinclude.phpãã¡ã€ã«ããããŸãã
namespace Olof\Iblock; use Bitrix\Main\Loader; // Loader::includeModule("Olof.Iblock"); // Api Loader::registerAutoLoadClasses("Olof.Iblock", [ "\Olof\Classes\Api" => ". /modules/Olof.Iblock/classes/api.php", ]); // : // Olof\Iblock\Element -> ./modules/Olof.Iblock/lib/Element.php // Olof\Classes\Api -> ./modules/Olof.Iblock/classes/api.php // Olof\Classes\Help -> ./modules/Olof.Classes/lib/Help.php
ç§ã®æèŠã§ã¯ãæé»ã®äºæãæ¡ä»¶ãå€ãããŸãã ãããŠãææ¥ãBitrixãã©ããªæãããæãä»ãã®ã誰ãç¥ããªãã ãããŠãPSR-4ã®ããã«ãããŒã ã¹ããŒã¹ãã¬ãã£ãã¯ã¹ã®ãã£ã¬ã¯ããªã瀺ãå¿ èŠãããããã®åŸã¯ã¯ãŒã«ã«ãªããŸãã ãããŸã§ã®éããžã£ã¬ãŒããŒããããŸã;-)
ã¢ã¯ãã£ãã¬ã³ãŒã
ãšã³ãã£ãã£ãç¹ã«æ å ±ãããã¯ãæäœããããã«ãActiveRecordãã³ãã¬ãŒããå®è£ ãããŠããŸãã çŸæç¹ã§ã¯ãARã¯Bitrix DataMappersã«åºã¥ããŠããïŒå®éã«ã¯ã¢ããªã³ïŒãå°æ¥çã«ã¯å®å šã«ç¬ç«ããORM / DAOã«ç§»è¡ããäºå®ã§ãã
以äžã¯ãARãä»ããŠã€ã³ãã©ãããã¯ãæäœããäŸã§ããå®éã«çŸåšå©çšå¯èœãªãã¹ãŠã®æ¹æ³ãã«ããŒãããŠããŸãã
ã³ãŒã
use Jugger\Db\Orm\Ib\Iblock; use Jugger\Db\Orm\Ib\IblockSection; use Jugger\Db\Orm\Ib\IblockElement; /* * */ $iblock = Iblock::getByPrimary(1); $iblock = Iblock::getRowByField("=ID", 1); $iblock = Iblock::getRow([ "filter" => [ "=ID" => 1, ], ]); $iblock = new Iblock($iblock); /** * , */ $iblock->NAME; $iblock->IBLOCK_TYPE_ID; /** * */ $iblock->getElements(); $iblock->getSections(); /* * */ $sectionList = $iblock->getSections(); $sectionList = $iblock->getSections([ "order" => [ "NAME" => "ASC", ], ]); $sectionList = IblockSection::getListByField("=IBLOCK_ID", $iblock->ID); $sectionList = IblockSection::getList([ "filter" => [ "=IBLOCK_ID" => $iblock->ID, ], ]); /* * */ $section = new IblockSection($sectionList->fetch()); $section->getChilds(); // 1- $section->getChilds(2); // 2- ( , ) $section->getChilds(0); // $section->getIblock(); // /* * */ $elementList = $section->getElements(); while($element = $elementList->fetch()) { /* * AR */ $element = new IblockElement($element); $element->getProperties(); // /* * */ $elementProperty = $element->getProperty(1); /* * ( ) */ $value = $elementProperty->VALUE; $value = $elementProperty->getValue(); /* * , * */ $elementProperty->getValueRaw(); // $elementProperty->getValueEnum(); // IblockPropertyEnum - (L) $elementProperty->getValueFile(); // CFile::GetFileArray $elementProperty->getValueHtml(); // (string) HTML $elementProperty->getValueElement(); // IblockElement - (E) $elementProperty->getValueSection(); // IblockSection - (G) $elementProperty->getValueNumber(); // (float) (int) /* * */ $property = $elementProperty->getMeta(); $property->NAME; $property->HINT; }
ã¡ãœããïŒ getPrimary ã getRow ã getRowByField ã getList ã getListByField-ãã¹ãŠã®ActiveRecordã§åäžã§ãã
ARã®æ©èœã¯çŸåšããªã貧匱ã§ãïŒããšãã°ãããŒãã«ã«ã¯ãã¹ãµãŒãã¯ãããŸããïŒãããããã¯æšæºé¢æ°ã®ã©ãããŒã§ãããããgetListããã³getRowã¡ãœããã§Bitrixãã³ã䜿çšã§ããŸãã éåžžã®DAOãäœæ/åçšããåŸããã®ç¬éã¯å®äºããŸãã
éºç£
Bitrixã®åŒ·ã¿ã¯ãå€ãã®äººãåæãããšæããŸããããã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãã€ãŸãHermitageã§ãã éåžžã«äŸ¿å©ã§æè»ã§ãã
以äžã¯ããšã«ãã¿ãŒãžã¥ã®äœ¿çšäŸã§ãã
ã³ãŒã
use Jugger\Db\Orm\Ib\IblockSection; use Jugger\Db\Orm\Ib\IblockElement; use Jugger\Ui\Hermitage; use Jugger\Ui\Hermitage\Icon; use Jugger\Context\UrlManager\Iblock; /* @var $this CBitrixComponentTemplate */ /* @var $component CBitrixComponent */ /* * "" "" */ $element = IblockSection::getByPrimary(1); Hermitage::addButtonEditIblockElement($this, $element); Hermitage::addButtonDeleteIblockElement($this, $element); $section = IblockSection::getByPrimary(1); Hermitage::addButtonEditIblockSection($this, $section); Hermitage::addButtonDeleteIblockSection($this, $section); /* * */ Hermitage::addButton( $component, Iblock::getElementCreateUrl(1), " ", [ "ICON" => Icon::TOOLBAR_CREATE, ] ); /* * */ Hermitage::addPanelButton("#", "", [ "ICON" => Icon::PANEL_TRANSLATE, ]);
éåžžã«è³è³ãããæžãããŠããããšã¯ã»ãšãã©ãããŸããïŒïŒå®éãããã¯ãŠãŒã¶ãŒãšã®å¯Ÿè©±ã«ååã§ãã 管çã€ã³ã¿ãŒãã§ã€ã¹ã«é¢ããŠå€ãã®å®è£ ãå¿ èŠã§ãããããã¯ãã¯ãHermitageã§ã¯ãªããããã¯ãã¹ãŠèšç»ã«å«ãŸããŠããŸãã
å®å šæ§
ç§ãBitrixã§ç¥ã£ãŠããéãïŒãããŠããã®åé¡ã§ãããé ããŸãããç§ã¯å®éã«ãããåé¿ããŸããã§ããïŒãããã¯ãµã€ãã»ãã¥ãªãã£ïŒã³ãŒãå ïŒã§äžè¬çã«æ²ããã§ãïŒSIä¿è·ã®ã¿ïŒã å°æ¥ããã®ã»ã¯ã·ã§ã³ã«ã¯ãããŸããŸãªæ»æãæªæã®ããã¢ã¯ã·ã§ã³ïŒXSSãã©ã³ãã ããŒã¿çæãããŸããŸãªæå·åæ©èœããã©ãŒã æ€èšŒããã¹ã¯ãŒãã®æäœãªã©ïŒããä¿è·ããããã®ããŒã«ãå«ãŸããŸãã çŸæç¹ã§ã¯ãCSRFä¿è·ããŒã«ã®ã¿ãå®è£ ãããŠããŸãã
use Jugger\Security\Csrf; /* * "" */ if (Csrf::validateTokenByPost()) { // ok } else { // error } echo Csrf::printInput(); /* * "" */ $nameField = "csrf"; $token = Bitrix\Main\Context::getCurrent()->getRequest()->getPost($nameField); if (Csrf::validateToken($token)) { // ok } else { // error } $token = Csrf::createToken(); echo "<input type='hidden' name='{$nameField}' value='{$token}'>";
åãã§ãã¯ã®åŸïŒæåãŸãã¯å€±æïŒ-ããŒã¯ã³ã¯ã»ãã·ã§ã³ããåé€ããããããããŒã¯ã³ã¯1åãããã§ãã¯ã§ããŸããã
Urlmanager
Bitrixãžã®ã«ãŒãã£ã³ã°ãç§ã¯é«åºŠã§ããããããã®ãšãªã¢ã¯ãžã£ã¬ãŒããŒãã§ã圱é¿ãåããŠãããšã¯èšããŸããã ãã®ã¯ã©ã¹ã䜿çšãããšãURLã«ãŒãïŒã«ãŒã¿ãŒã³ã³ããŒãã³ãã§äœ¿çšïŒãåçã«äœæããŠäœ¿çšã§ããŸãã
URLã®è§£æãšçæã®äŸãèããŠã¿ãŸãããã
ã³ãŒã
use Jugger\Context\UrlManager; /* * URL */ UrlManager::setBaseUrl("/catalog"); UrlManager::addAlias("sectionList", "index.php"); UrlManager::addAlias("elementList", "#SECTION_CODE#/"); UrlManager::addAlias("elementView", "#SECTION_CODE#/#ELEMENT_CODE#/"); /* * 'alias' * , '/catalog/section1/element1/' 'elementView' */ $alias = UrlManager::parseRequest(); /* * ( UrlManager , ) */ $folder404 = "/catalog"; $arUrlTemplates = [ "sectionList" => "index.php", "elementList" => "#SECTION_CODE#/", "elementView" => "#SECTION_CODE#/#ELEMENT_CODE#/", ]; $arVariables = []; // UrlManager::$params CComponentEngine::parseComponentPath($folder404, $arUrlTemplates, $arVariables); /* * */ UrlManager::addParams([ "param1" => "value1", "param2" => "value2", ]); /* * URL. * . * "ELEMENT_CODE" - */ UrlManager::addParam("SECTION_CODE", "section1"); $url = UrlManager::build("elementView", [ "ELEMENT_CODE" => "element1", ]); // $url: /catalog/section1/element1/
å°æ¥çã«ã¯ã urlRewrite.phpã«æ¥ç¶ããããšãèšç»ãããŠããŸã ã
ã€ãã³ã
ãã®ã¯ã©ã¹ã¯ãD7ã®æ©èœã®åãªãã©ãããŒã§ããããã䟿å©ã«äœ¿çšã§ããŸãã
use Jugger\Helper\Event; /* * */ Event::on(" ", function(){ // }); Event::on(" ", "\ClassName::MethodName", "moduleName"); /* * */ Event::off(" "); Event::off(" ", 3); // 4- ( ) /* * */ Event::trigger(" "); /* * () */ Event::trigger(" ", $this);
次ã¯ïŒ
è¿ãå°æ¥ã®èšç»ïŒ
- éåžžã®QueryBuilder
- éåžžã®ãã£ãã·ã³ã°
- éåžžã®AssetsManager
- 管çã€ã³ã¿ãŒãã§ãŒã¹ãäœæããã³æäœããããã®ã³ã³ããŒãã³ãã®ã»ãã
- éåžžã®ã«ãŒãã£ã³ã°ïŒHttpExceptionã«é¢é£ä»ããããŠããŸãïŒ
ãããã«
å€ãã®ããšãèšç»ãããŠããŸãããå€ãã®ããšãè¡ãããŠããŸããã ã©ã€ãã©ãªã¯å¿ èŠã«å¿ããŠéçºããããããçŸåšã®æ³šæïŒå€ãã®å Žååãã¿ã€ãïŒãšç©ºãæéã«å€§ããäŸåããŸãã
åé ã§è¿°ã¹ãããã«ããããžã§ã¯ãã¯ãã¹ãŠã«ããããããéçºãããŸããéçºã®é床ã®ã¿ããäœæè ãšé¢ä¿è ã®æ°ã«äŸåããŸãã ãããã£ãŠãéžæã¯ããªã次第ã§ãã
- æ³£ãèšãèšã£ãŠãåŸ ã£ãŠãBitrixã«èª¿æŽããŸãïŒãããŠãBitrixFrameworkã®éçºã¯æããã«åªå äºé ã§ã¯ãããŸããïŒã
- ãã¹ãŠãèªåã®æã«åãããžã£ã¬ãŒããŒãã®éçºãæäŒã£ãŠãã ããã
ããªããå¿ èŠãšãããã®ããã«ãåžæããæ å家ã¯å©ããããšãã§ããŸãïŒããã§ãªããã°ãæ¹æ³ã¯ãããŸããïŒïŒ
- ã¢ã€ãã¢ãå ±æãã
- ãªãã¡ã¯ã¿ãªã³ã°
- ãã³ã§äœãããã
ãã®ãããžã§ã¯ãã¯GitHubã«ããããã誰ã§ãç·šéãè¿œå ãã³ã¡ã³ãã質åãã§ããŸãã
ãæž èŽããããšãããããŸããïŒ å»ºèšçãªæ¹å€ã¯å€§æè¿ã§ã:-)
PSã¯ããFIG Bitrixã®ã¯ããã®ãããªãæžã蟌ã¿ãããªããšãã巚倧ãªèŠæ±ãã³ã¡ã³ãããŠããŸãã ç§ã¯äººã ããã®ã·ã¹ãã ã§äœãããªããã°ãªããªãããç¥ã£ãŠããŸãããããŠããã®ãããžã§ã¯ãã¯ã¡ããã©ãããæ¹åããããšãç®æããŠããŸãã ãããã£ãŠããä»»æã®ãã¬ãŒã ã¯ãŒã¯ã§ãããžã§ã¯ããäœæããæ¹ãããç°¡åã§ç°¡åã ããšæãå Žåããããç¥ã£ãŠãããããªãã«ãšã£ãŠéåžžã«æºè¶³ããŠããã®ã§ãããªãèªèº«ã®æèŠãæ®ããŠãã ããã ãããããé¡ãããŸãïŒ
ãªããžããªïŒ github.com/irpsv/juggernaut.bitrix_release
ããŒã±ãããã¬ã€ã¹ïŒè¿æ¥å ¬é