2013-05-17 5 views
3

파일에는 메뉴, 검색 등 모든 헤더 부분이 들어있는 후크 {$HOOK_TOP}이 있습니다.이 URL에서 확인할 수 있습니다prestashop의 Hook.php에서 exec() 함수를 사용하는 목적은 무엇입니까

FrontController에서 ... 'HOOK_TOP' => Hook::exec('displayTop'), 은 훅 페이지에 exec()이라는 기능이 있음을 의미합니다. 그러나 exec() 호출에서 코드를 제대로 이해할 수 없습니다.

알려줍니다. 지정된 후크에 대해 모듈을 실행하십시오.. "displayTop"을 검색했을 때 blocktopmenu.php이라는 모듈 이름이 있습니다.

public function hookDisplayTop($param) 
    { 
     $this->user_groups = ($this->context->customer->isLogged() ? $this->context->customer->getGroups() : array(Configuration::get('PS_UNIDENTIFIED_GROUP'))); 
     $this->page_name = Dispatcher::getInstance()->getController(); 
     if (!$this->isCached('blocktopmenu.tpl', $this->getCacheId())) 
     { 
      $this->makeMenu(); 
      $this->smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH')); 
      $this->smarty->assign('MENU', $this->_menu); 
      $this->smarty->assign('this_path', $this->_path); 
     } 

     $this->context->controller->addJS($this->_path.'js/hoverIntent.js'); 
     $this->context->controller->addJS($this->_path.'js/superfish-modified.js'); 
     $this->context->controller->addCSS($this->_path.'css/superfish-modified.css'); 

     $html = $this->display(__FILE__, 'blocktopmenu.tpl', $this->getCacheId()); 
     //print_r($html);//exit; 
     return $html; 
    } 

protected function getCacheId($name = null) 
{//echo"asdasdsad";exit; 
    parent::getCacheId($name); 
    $page_name = in_array($this->page_name, array('category', 'supplier', 'manufacturer', 'cms', 'product')) ? $this->page_name : 'index'; 
    return 'blocktopmenu|'.(int)Tools::usingSecureMode().'|'.$page_name.'|'.(int)$this->context->shop->id.'|'.implode(', ',$this->user_groups).'|'.(int)$this->context->language->id.'|'.(int)Tools::getValue('id_category').'|'.(int)Tools::getValue('id_manufacturer').'|'.(int)Tools::getValue('id_supplier').'|'.(int)Tools::getValue('id_cms').'|'.(int)Tools::getValue('id_product'); 
} 

을하지만 공공 기능 hookDisplayTop($param)은 결코 아무 곳이나 전체 폴더에 호출되지 가져옵니다

실행에만이 개 기능을 통해 간다. 나는 그것을 찾았지만 그것을 결코 어떤 파일에서도 발견하지 못했다.

exec() 기능은 HookDiplayTop 전화

public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true) 
    { 

     // Check arguments validity 
     if (($id_module && !is_numeric($id_module)) || !Validate::isHookName($hook_name)) 
      throw new PrestaShopException('Invalid id_module or hook_name'); 

     // If no modules associated to hook_name or recompatible hook name, we stop the function 

     if (!$module_list = Hook::getHookModuleExecList($hook_name)) 
      return ''; 

     // Check if hook exists 
     if (!$id_hook = Hook::getIdByName($hook_name)) 
      return false; 

     // Store list of executed hooks on this page 

     Hook::$executed_hooks[$id_hook] = $hook_name; 
    // print_r(Hook::$executed_hooks);exit; 

     $live_edit = false; 
     $context = Context::getContext(); 
     if (!isset($hook_args['cookie']) || !$hook_args['cookie']) 
      $hook_args['cookie'] = $context->cookie; 
     if (!isset($hook_args['cart']) || !$hook_args['cart']) 
      $hook_args['cart'] = $context->cart; 

     $retro_hook_name = Hook::getRetroHookName($hook_name); 
//print_r($hook_name);exit; 
     // Look on modules list 
     $altern = 0; 
     $output = ''; 
     foreach ($module_list as $array) 
     { 
      // Check errors 
      if ($id_module && $id_module != $array['id_module']) 
       continue; 
      if (!($moduleInstance = Module::getInstanceByName($array['module']))) 
       continue; 

      // Check permissions 
      if ($check_exceptions) 
      { 
       $exceptions = $moduleInstance->getExceptions($array['id_hook']); 
       $controller = Dispatcher::getInstance()->getController(); 

       if (in_array($controller, $exceptions)) 
        continue; 

       //retro compat of controller names 
       $matching_name = array(
        'authentication' => 'auth', 
        'compare' => 'products-comparison', 
        ); 
       if (isset($matching_name[$controller]) && in_array($matching_name[$controller], $exceptions)) 
        continue; 
       if (Validate::isLoadedObject($context->employee) && !$moduleInstance->getPermission('view', $context->employee)) 
        continue; 
      } 

      // Check which/if method is callable 
      $hook_callable = is_callable(array($moduleInstance, 'hook'.$hook_name)); 
      $hook_retro_callable = is_callable(array($moduleInstance, 'hook'.$retro_hook_name)); 
      if (($hook_callable || $hook_retro_callable) && Module::preCall($moduleInstance->name)) 
      { 
       $hook_args['altern'] = ++$altern; 

       // Call hook method 
       if ($hook_callable) 
        $display = $moduleInstance->{'hook'.$hook_name}($hook_args); 
       else if ($hook_retro_callable) 
        $display = $moduleInstance->{'hook'.$retro_hook_name}($hook_args); 
       // Live edit 
       if (!$array_return && $array['live_edit'] && Tools::isSubmit('live_edit') && Tools::getValue('ad') && Tools::getValue('liveToken') == Tools::getAdminToken('AdminModulesPositions'.(int)Tab::getIdFromClassName('AdminModulesPositions').(int)Tools::getValue('id_employee'))) 
       { 
        $live_edit = true; 
        $output .= self::wrapLiveEdit($display, $moduleInstance, $array['id_hook']); 
       } 
       else if ($array_return) 
        $output[] = $display; 
       else 
        $output .= $display; 
      } 
     } 
     if ($array_return) 
      return $output; 
     else 
      return ($live_edit ? '<script type="text/javascript">hooks_list.push(\''.$hook_name.'\'); </script> 
       <div id="'.$hook_name.'" class="dndHook" style="min-height:50px">' : '').$output.($live_edit ? '</div>' : '');// Return html string 
    } 
+1

아마도 후크 방법은 이미 언급 한 exec() 메소드에서 동적으로 호출됩니다. 그냥 exec() 메서드의 내용을 게시하고 내가 그걸 줄께요 – thpl

+0

게시 됨, @ @ ThomsDavidPlat을 확인하십시오 –

+0

@Xavier du Tertre .. prestashop에서 blocktopmenu 모듈 만 호출하는 방법을 말해 줄 수 있습니다 ... 사용한다면 displayTop 후크 그것과 함께 다양한 다른 모듈을 호출 ..하지만 나는 blocktopmenu 클래스를 호출하고 해당 클래스의 hookDisplayTop()에 액세스 할 수 있습니다. 그래서 다른 모듈은 피할 수 있습니다. .. 시도했지만 그 작동하지 않습니다 –

답변

4

난 당신이 여기에 코드 라인을 설명하지 않을거야,하지만 난 당신을 설명 할 것입니다 무엇을 exec 정적 멤버 do. 당신이

Hook::exec("HookName"); 

전화 이제까지

언제 그것은 당신을 위해 다음과 같은 과정을 수행한다.

1) 먼저 훅이 사용 가능한지 여부를 확인합니다. 사용할 수없는 경우 false를 반환합니다.

2) 두 번째로 데이터베이스에서 해당 후크에 대한 모듈 목록을 가져옵니다. 또한 현재 페이지의 후크 모듈에 대한 예외로 목록의 범위를 좁 힙니다.

3) 현재로드 된 (또는 호출 된 페이지) 페이지를 호출하는 후크의 모든 모듈을 가져온 후 모듈의 후크 기능을 호출합니다. 특정 후크에 대한 모듈을 검사하면 해당 후크에 대한 공개 기능을 찾을 수 있습니다. 톱 후크를 고려해 보자. 모듈에서 당신은 공개 기능을 갖습니다.

public function hookTop // or public function hookDisplayTop for compatibility reasons 

PS는 다른 작업도 수행하지 마십시오.

위의 내용은 PS에서 후크와 모듈이 어떻게 작동 하는지를 보여줍니다. 또한 위의 이론을 바탕으로, 저는 Codeigniter와 Zend Framework에서 동일한 프로젝트를 구현하여 매력적으로 작동합니다.).

다른 질문이있는 경우 알려 주시면 최대한 자세히 알려 드리겠습니다.

+0

프론트 엔드 흐름을 설명해 줄 수 있습니다. 도움이 될 것입니다. –

+0

어떤 흐름이 필요합니까? 모듈 또는 PS 작업용? –

+0

PrestaShop 작업 –

1

라인 아래에 표시됩니다

// Call hook method 
if ($hook_callable) 
$display = $moduleInstance->{'hook'.$hook_name}($hook_args); 
else if ($hook_retro_callable) 
$display = $moduleInstance->{'hook'.$retro_hook_name}($hook_args); 
+0

그래, 나는 당신과 동의합니다 ..하지만 모듈의 blocktopmenu가 호출되는 방법을 설명 할 수 .. 실행의 perticular 흐름 ... 그리고 왜 공공 기능 hookDisplayTop ($ param)을 실행 가져옵니다 결코 어디에도 전화하지 마라. 그것은 가능한가? ??? –

+0

아직 설명서에 설명되어 있지 않습니다. http://doc.prestashop.com/display/PS15/Diving+into+PrestaShop+Core+development#DivingintoPrestaShopCoredevelopment-FrontController 클래스 의견을 보내 주셔서 감사합니다. –

관련 문제