Development

HowtoServeStaticContent (diff)

You must first sign up to be able to contribute.

Changes between Version 6 and Version 7 of HowtoServeStaticContent

Show
Ignore:
Author:
bgunderson (IP: 24.16.121.183)
Timestamp:
02/06/07 09:23:35 (11 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HowtoServeStaticContent

    v6 v7  
    5656}}} 
    5757 
     58== Checking if the partial exists from within the action == 
     59 
     60You may wish to add logic to forward to a 404 page if the static content being requested doesn't exist. This snippet defines a helper function to check if the partial is readable from within the action and forward to the 404 page if not. 
     61 
     62=== actions.class.php === 
     63 
     64{{{ 
     65class staticActions extends sfActions { 
     66   public function executeIndex() { 
     67      $this->content = $this->getRequestParameter("content"); 
     68          
     69      $context = $this->getContext(); 
     70          
     71      $this->forward404Unless($this->partialExists($context, $this->content)); 
     72   } 
     73       
     74   protected function partialExists($context, $name) { 
     75      $directory = $context->getModuleDirectory(); 
     76                                                      
     77      if (is_readable($directory . DIRECTORY_SEPARATOR ."templates". DIRECTORY_SEPARATOR ."_". $name .".php")) { 
     78         return true; 
     79      } else { 
     80         return false; 
     81      } 
     82   } 
     83} 
     84}}} 
     85 
    5886== Credits == 
    5987