Example #1
0
 public static function __init()
 {
     \minerva\models\Page::applyFilter('find', function ($self, $params, $chain) {
         /**
          * find() doens't do anything with a "request_params" key and you wouldn't typically see it...
          * However, all core Minerva code will pass the request params to all find() calls just for
          * this kind of flexibility. In this case, if it's not an admin action then we're adding to the
          * conditions the requirement of the document being published.
          *
          * Note that this filter is applied to the core Minerva Page model.
          * So as long as this model gets called, it will apply the published condition to all finds
          * for all pages. Keep in mind the order in which filters are applied and when libraries are added.
          * It's probably best to apply this sort of filter as self::applyFilter() instead so that we are
          * more certain of when it's used. The filter can also be defined below outside of the class.
          *
          * What else could we do here? We could say certain users could see it on non-admin actions too...
          * Or...whatever else that could be dreamed of.
          */
         if (!isset($params['options']['request_params']['admin']) || empty($params['options']['request_params']['admin'])) {
             $params['options']['conditions']['published'] = true;
         }
         return $chain->next($self, $params, $chain);
         // NOTE: could be applying access rules here and checking against them
         //$record = $chain->next($self, $params, $chain);
         // Here would be an "afterFind" don't forget to return $record; instead of to the chain
         //var_dump($record);
     });
     // Put any desired filters here
     parent::__init();
 }
Example #2
0
	public static function __init() {
		
		\minerva\models\Page::applyFilter('find', function($self, $params, $chain) {
		    
            /**
             * find() doens't do anything with a "request_params" key and you wouldn't typically see it...
             * However, all core Minerva code will pass the request params to all find() calls just for
             * this kind of flexibility. In this case, if it's not an admin action then we're adding to the
             * conditions the requirement of the document being published.
             *
             * What else could we do? We could say certain users could see it on non-admin actions too...
             * Or...whatever else that could be dreamed of.
            */
            if((isset($params['options']['request_params']['admin'])) && ($params['options']['request_params']['admin'] !== true)) {
                $params['options']['conditions']['published'] = true;
            }
		    
		    return $chain->next($self, $params, $chain);
		    
		    // NOTE: could be applying access rules here and checking against them
		    //$record = $chain->next($self, $params, $chain);
		    // Here would be an "afterFind" don't forget to return $record; instead of to the chain
		    //var_dump($record);
		    
		});
		
		// Put any desired filters here
		
		parent::__init();
	}