extends abstract class Phalcon\Di\Injectable
implements Phalcon\Events\EventsAwareInterface, Phalcon\Di\InjectionAwareInterface, Phalcon\Mvc\Model\ManagerInterface
This components controls the initialization of models, keeping record of relations between the different models of the application. A ModelsManager is injected to a model via a Dependency Injector/Services Container such as Phalcon\Di.
<?php
$di = new Phalcon\Di();
$di->set('modelsManager', function() {
return new Phalcon\Mvc\Model\Manager();
});
$robot = new Robots($di);
public setCustomEventsManager (Phalcon\Mvc\ModelInterface $model, Phalcon\Events\ManagerInterface $eventsManager)
Sets a custom events manager for a specific model
public Phalcon\Events\ManagerInterface getCustomEventsManager (Phalcon\Mvc\ModelInterface $model)
Returns a custom events manager related to a model
public boolean initialize (Phalcon\Mvc\ModelInterface $model)
Initializes a model in the model manager
public boolean isInitialized (string $modelName)
Check whether a model is already initialized
public Phalcon\Mvc\ModelInterface getLastInitialized ()
Get last initialized model
public Phalcon\Mvc\ModelInterface load (string $modelName, boolean $newInstance)
Loads a model throwing an exception if it doesn’t exist
public string setModelSource (Phalcon\Mvc\Model|string $model, string $source)
Sets the mapped source for a model
public string getModelSource (Phalcon\Mvc\Model|string $model)
Returns the mapped source for a model
public string setModelSchema (Phalcon\Mvc\Model $model, string $schema)
Sets the mapped schema for a model
public string getModelSchema (Phalcon\Mvc\Model $model)
Returns the mapped schema for a model
public setConnectionService (Phalcon\Mvc\ModelInterface $model, string $connectionService)
Sets both write and read connection service for a model
public setWriteConnectionService (Phalcon\Mvc\ModelInterface $model, string $connectionService)
Sets write connection service for a model
public setReadConnectionService (Phalcon\Mvc\ModelInterface $model, string $connectionService)
Sets read connection service for a model
public setDefaultConnectionService (string $connectionService)
Sets default connection service for a model
public string getDefaultConnectionService ()
Gets default connection service for a model
public setDefaultWriteConnectionService (string $connectionService)
Sets default write connection service for a model
public string getDefaultWriteConnectionService ()
Gets default write connection service for a model
public setDefaultReadConnectionService (string $connectionService)
Sets default read connection service for a model
public string getDefaultReadConnectionService ()
Gets default read connection service for a model
public Phalcon\Db\AdapterInterface getWriteConnection (Phalcon\Mvc\ModelInterface $model)
Returns the connection to write data related to a model
public Phalcon\Db\AdapterInterface getReadConnection (Phalcon\Mvc\ModelInterface $model)
Returns the connection to read data related to a model
public getReadConnectionService (Phalcon\Mvc\ModelInterface $model)
Returns the connection service name used to read data related to a model
public getWriteConnectionService (Phalcon\Mvc\ModelInterface $model)
Returns the connection service name used to write data related to a model
public notifyEvent (string $eventName, Phalcon\Mvc\ModelInterface $model)
Receives events generated in the models and dispatches them to a events-manager if available Notify the behaviors that are listening in the model
public boolean missingMethod (Phalcon\Mvc\ModelInterface $model, string $eventName, array $data)
Dispatch a event to the listeners and behaviors This method expects that the endpoint listeners/behaviors returns true meaning that a least one is implemented
public addBehavior (Phalcon\Mvc\ModelInterface $model, Phalcon\Mvc\Model\BehaviorInterface $behavior)
Binds a behavior to a model
public useDynamicUpdate (Phalcon\Mvc\Model $model, boolean $dynamicUpdate)
Sets if a model must use dynamic update instead of the all-field update
public boolean isUsingDynamicUpdate (unknown $model)
Checks if a model is using dynamic update instead of all-field update
public Phalcon\Mvc\Model\Relation addHasOne (Phalcon\Mvc\Model $model, mixed $fields, string $referencedModel, mixed $referencedFields, [array $options])
Setup a 1-1 relation between two models
public Phalcon\Mvc\Model\Relation addBelongsTo (Phalcon\Mvc\Model $model, mixed $fields, string $referencedModel, mixed $referencedFields, [array $options])
Setup a relation reverse many to one between two models
public addHasMany (Phalcon\Mvc\ModelInterface $model, mixed $fields, string $referencedModel, mixed $referencedFields, [array $options])
Setup a relation 1-n between two models
public Phalcon\Mvc\Model\Relation addHasManyToMany (unknown $model, string $fields, string $intermediateModel, string $intermediateFields, string $intermediateReferencedFields, string $referencedModel, string $referencedFields, [array $options])
Setups a relation n-m between two models
public boolean existsBelongsTo (string $modelName, string $modelRelation)
Checks whether a model has a belongsTo relation with another model
public boolean existsHasMany (string $modelName, string $modelRelation)
Checks whether a model has a hasMany relation with another model
public boolean existsHasOne (string $modelName, string $modelRelation)
Checks whether a model has a hasOne relation with another model
public boolean existsHasManyToMany (string $modelName, string $modelRelation)
Checks whether a model has a hasManyToMany relation with another model
public Phalcon\Mvc\Model\Relation getRelationByAlias (string $modelName, string $alias)
Returns a relation by its alias
public Phalcon\Mvc\Model\Resultset\Simple getRelationRecords (Phalcon\Mvc\Model\Relation $relation, string $method, Phalcon\Mvc\ModelInterface $record, [array $parameters])
Helper method to query records based on a relation definition
public object getReusableRecords (string $modelName, string $key)
Returns a reusable object from the internal list
public setReusableRecords (string $modelName, string $key, mixed $records)
Stores a reusable record in the internal list
public clearReusableObjects ()
Clears the internal reusable list
public Phalcon\Mvc\Model\ResultsetInterface getBelongsToRecords (string $method, string $modelName, string $modelRelation, Phalcon\Mvc\Model $record, [array $parameters])
Gets belongsTo related records from a model
public Phalcon\Mvc\Model\ResultsetInterface getHasManyRecords (string $method, string $modelName, string $modelRelation, Phalcon\Mvc\Model $record, [array $parameters])
Gets hasMany related records from a model
public Phalcon\Mvc\Model\ResultsetInterface getHasOneRecords (string $method, string $modelName, string $modelRelation, Phalcon\Mvc\Model $record, [array $parameters])
Gets belongsTo related records from a model
public Phalcon\Mvc\Model\RelationInterface [] getBelongsTo (Phalcon\Mvc\ModelInterface $model)
Gets all the belongsTo relations defined in a model
<?php
$relations = $modelsManager->getBelongsTo(new Robots());
public Phalcon\Mvc\Model\RelationInterface [] getHasMany (Phalcon\Mvc\ModelInterface $model)
Gets hasMany relations defined on a model
public array getHasOne (Phalcon\Mvc\ModelInterface $model)
Gets hasOne relations defined on a model
public Phalcon\Mvc\Model\RelationInterface [] getHasManyToMany (Phalcon\Mvc\ModelInterface $model)
Gets hasManyToMany relations defined on a model
public array getHasOneAndHasMany (Phalcon\Mvc\ModelInterface $model)
Gets hasOne relations defined on a model
public Phalcon\Mvc\Model\RelationInterface [] getRelations (string $modelName)
Query all the relationships defined on a model
public Phalcon\Mvc\Model\RelationInterface getRelationsBetween (string $first, string $second)
Query the first relationship defined between two models
public Phalcon\Mvc\Model\QueryInterface createQuery (string $phql)
Creates a Phalcon\Mvc\Model\Query without execute it
public Phalcon\Mvc\Model\QueryInterface executeQuery (string $phql, [array $placeholders])
Creates a Phalcon\Mvc\Model\Query and execute it
public Phalcon\Mvc\Model\Query\BuilderInterface createBuilder ([string $params], [unknown $type])
Creates a Phalcon\Mvc\Model\Query\Builder
public Phalcon\Mvc\Model\QueryInterface getLastQuery ()
Returns the lastest query created or executed in the models manager
public registerNamespaceAlias (string $alias, string $namespace)
Registers shorter aliases for namespaces in PHQL statements
public string getNamespaceAlias (string $alias)
Returns a real namespace from its alias
public array getNamespaceAliases ()
Returns all the registered namespace aliases
public __destruct ()
Destroys the PHQL cache
public setDI (Phalcon\DiInterface $dependencyInjector) inherited from Phalcon\Di\Injectable
Sets the dependency injector
public Phalcon\DiInterface getDI ([unknown $error], [unknown $notUseDefault]) inherited from Phalcon\Di\Injectable
Returns the internal dependency injector
public setEventsManager (Phalcon\Events\ManagerInterface $eventsManager) inherited from Phalcon\Di\Injectable
Sets the event manager
public Phalcon\Events\ManagerInterface getEventsManager () inherited from Phalcon\Di\Injectable
Returns the internal event manager
public boolean fireEvent (string $eventName, [mixed $data], [unknown $cancelable]) inherited from Phalcon\Di\Injectable
Fires an event, implicitly calls behaviors and listeners in the events manager are notified
public mixed fireEventCancel (string $eventName, [mixed $data], [unknown $cancelable]) inherited from Phalcon\Di\Injectable
Fires an event, can stop the event by returning to the false
public boolean hasService (string $name) inherited from Phalcon\Di\Injectable
Check whether the DI contains a service by a name
public Phalcon\Di\ServiceInterface setService (unknown $name) inherited from Phalcon\Di\Injectable
Sets a service from the DI
public object|null getService (unknown $name) inherited from Phalcon\Di\Injectable
Obtains a service from the DI
public mixed getResolveService (string $name, [array $args], [unknown $noerror], [unknown $noshared]) inherited from Phalcon\Di\Injectable
Resolves the service based on its configuration
public attachEvent (string $eventType, Closure $callback) inherited from Phalcon\Di\Injectable
Attach a listener to the events
public __get (unknown $property) inherited from Phalcon\Di\Injectable
Magic method __get
public __sleep () inherited from Phalcon\Di\Injectable
...
public __debugInfo () inherited from Phalcon\Di\Injectable
...