예제 #1
0
 /**
  * Parse request URL into components and return a corresponding MVC request object
  *
  * @return midgardmvc_core_helpers_request
  */
 public function get_request()
 {
     $request = new midgardmvc_core_helpers_request();
     $request->set_root_page($this->_root_page);
     $request->set_method($_SERVER['REQUEST_METHOD']);
     // Parse URL into components (Mjolnir doesn't do this for us)
     $url_components = parse_url("http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
     // Handle GET parameters
     if (!empty($url_components['query'])) {
         $get_parameters = array();
         parse_str($url_components['query'], $get_parameters);
         $request->set_query($get_parameters);
     }
     $request->resolve_page($url_components['path']);
     return $request;
 }
예제 #2
0
 /**
  * Parse request URL into components and return a corresponding MVC request object
  *
  * @return midgardmvc_core_helpers_request
  */
 public function get_request()
 {
     $request = new midgardmvc_core_helpers_request();
     $request->set_root_page(new midgardmvc_core_node($_MIDGARD['root']));
     $request->set_page(new midgardmvc_core_node($_MIDGARD['page']));
     $arg_string = substr($_MIDGARD['uri'], strlen($_MIDGARD['self']));
     $request_argv = array();
     if ($arg_string) {
         $argv = explode('/', $arg_string);
         foreach ($argv as $arg) {
             if (empty($arg)) {
                 continue;
             }
             $request_argv[] = $arg;
         }
     }
     $request->set_argv($request_argv);
     $request->set_method($_SERVER['REQUEST_METHOD']);
     $request->set_prefix($_MIDGARD['self']);
     if (isset($_GET)) {
         $request->set_query($_GET);
     }
     return $request;
 }
예제 #3
0
 /**
  * Call a route of a component with given arguments and return the data it generated
  *
  * Dynamic calls may be called for either a specific page that has a component assigned to it
  * by specifying a page GUID or path as the first argument, or to a static instance of a component
  * by specifying component name as the first argument.
  *
  * Here is an example of using dynamic calls inside a TAL template, in this case loading three latest news:
  * 
  * <code>
  * <tal:block tal:define="latest_news php:midgardmvc.templating.dynamic_call('net_nemein_news', 'latest', array('number' => 3))">
  *     <ul tal:condition="latest_news/news">
  *         <li tal:repeat="article latest_news/news">
  *             <a href="#" tal:attributes="href article/url" tal:content="article/title">Headline</a>
  *         </li>
  *     </ul>
  * </tal:block>
  * </code>
  *
  * @param string $component_name Component name, page GUID or page path
  * @param string $route_id     Route identifier
  * @param array $arguments  Arguments to give to the route
  * @param boolean $switch_context Whether to run the route in a new context
  * @return $array data
  */
 public function dynamic_call($component_name, $route_id, array $arguments, $switch_context = true)
 {
     if (is_null($this->dispatcher)) {
         $this->dispatcher = new midgardmvc_core_services_dispatcher_manual();
     }
     if ($switch_context) {
         $this->midgardmvc->context->create();
     }
     $request = new midgardmvc_core_helpers_request();
     if (is_object($component_name) && is_a($component_name, 'midgardmvc_core_node')) {
         $request->set_page($component_name);
     } elseif (mgd_is_guid($component_name)) {
         $request->set_page(new midgardmvc_core_node($component_name));
     } elseif (strpos($component_name, '/') !== false) {
         $request->resolve_page($component_name);
     } else {
         $request->set_component($component_name);
     }
     // Copy HTTP request method of main context to the request
     $request->set_method($this->midgardmvc->context->get_item('request_method', 0));
     $request->populate_context();
     // Run process injector for this context too
     $this->midgardmvc->componentloader->inject_process();
     // Then initialize the component, so it also goes to template stack
     $this->dispatcher->initialize($request);
     $this->dispatcher->set_route($route_id, $arguments);
     $this->dispatcher->dispatch();
     $component_name = $this->midgardmvc->context->component;
     $data = $this->midgardmvc->context->{$component_name};
     if ($switch_context) {
         $this->midgardmvc->context->delete();
     }
     return $data;
 }