FOF30\Model\Model::__construct PHP Method

__construct() public method

You can use the $config array to pass some configuration values to the object: state stdClass|array. The state variables of the Model. use_populate Boolean. When true the model will set its state from populateState() instead of the request. ignore_request Boolean. When true getState will not automatically load state data from the request.
public __construct ( Container $container, array $config = [] )
$container FOF30\Container\Container The configuration variables to this model
$config array Configuration values for this model
    public function __construct(Container $container, array $config = array())
    {
        $this->container = $container;
        // Set the model's name from $config
        if (isset($config['name'])) {
            $this->name = $config['name'];
        }
        // If $config['name'] is not set, auto-detect the model's name
        $this->name = $this->getName();
        // Set the model state
        if (array_key_exists('state', $config)) {
            if (is_object($config['state'])) {
                $this->state = $config['state'];
            } elseif (is_array($config['state'])) {
                $this->state = (object) $config['state'];
            } else {
                $this->state = new \stdClass();
            }
        } else {
            $this->state = new \stdClass();
        }
        // Set the internal state marker
        if (!empty($config['use_populate'])) {
            $this->_state_set = true;
        }
        // Set the internal state marker
        if (!empty($config['ignore_request'])) {
            $this->_ignoreRequest = true;
        }
    }

Usage Example

コード例 #1
0
ファイル: ModelStub.php プロジェクト: Joal01/fof
 /**
  * Assigns callback functions to the class, the $methods array should be an associative one, where
  * the keys are the method names, while the values are the closure functions, e.g.
  *
  * array(
  *    'foobar' => function(){ return 'Foobar'; }
  * )
  *
  * @param           $container
  * @param array     $config
  * @param array     $methods
  */
 public function __construct(Container $container, array $config = array(), array $methods = array())
 {
     foreach ($methods as $method => $function) {
         $this->methods[$method] = $function;
     }
     parent::__construct($container, $config);
 }
All Usage Examples Of FOF30\Model\Model::__construct