Behavior::load PHP Method

load() public static method

public static load ( $name )
    public static function load($name)
    {
        $filename = 'lib/behaviors/' . $name . '.php';
        if (!class_exists($name) && Filesystem::exists($filename)) {
            require $filename;
        }
        if (!class_exists($name)) {
            throw new RuntimeException('The behavior <code>' . $name . '</code> was not found.');
        }
    }

Usage Example

 public function __construct(&$page, $params)
 {
     /* Execute this behaviour only if page equals the current page.          */
     if (url_match($page->getUri())) {
         if ($child = $page->children(array('limit' => 1))) {
             header('Location: ' . $child->url());
             die;
         }
     } else {
         // find called page
         foreach ($params as $slug) {
             $page = Page::findBySlug($slug, $page);
         }
         // if found
         if ($page instanceof Page) {
             // check for behavior
             if ($page->behavior_id != '') {
                 // add a instance of the behavior with the name of the behavior
                 $page->{$page->behavior_id} = Behavior::load($page->behavior_id, $page, $params);
             }
         } else {
             // not found
             page_not_found($_SERVER['REQUEST_URI']);
         }
     }
 }
All Usage Examples Of Behavior::load