Model
- Full name:
\Zemit\Mvc\Controller\Traits\Model
Properties
modelName
The name of the model.
protected ?string $modelName
modelNamespaces
The namespaces for the model lookup.
protected string[] $modelNamespaces
Methods
getModelName
Retrieves the name of the model associated with the controller.
public getModelName(): string|null
Return Value:
The name of the model associated with the controller, or null if not found.
setModelName
Sets the name of the model to be used.
public setModelName(string|null $modelName): void
Parameters:
Parameter | Type | Description |
---|---|---|
$modelName | **string | null** |
getModelNamespaces
Gets the namespaces used for the model lookup.
public getModelNamespaces(): array
If no model namespace is set, the namespaces defined in the loader will be returned.
Return Value:
The namespaces used for the model lookup.
setModelNamespaces
Set the namespaces for the models.
public setModelNamespaces(array|null $modelNamespaces): void
Parameters:
Parameter | Type | Description |
---|---|---|
$modelNamespaces | **array | null** |
getModelNameFromController
Retrieves the model name from the controller by following certain naming conventions.
public getModelNameFromController(array|null $namespaces = null, string $needle = 'Models'): string|null
Parameters:
Parameter | Type | Description |
---|---|---|
$namespaces | **array | null** |
$needle | string | Optional. The keyword to search for in the namespace. Default is 'Models'. |
Return Value:
The model name if found, otherwise null.
getControllerName
Returns the name of the controller.
public getControllerName(): string
If the controller name is not set in the dispatcher, it extracts the controller name from the class name of the current instance.
Return Value:
The name of the controller.
loadModel
Loads a model by its name using the modelsManager.
public loadModel(string|null $modelName = null): \Phalcon\Mvc\ModelInterface
Parameters:
Parameter | Type | Description |
---|---|---|
$modelName | **string | null** |
Return Value:
The loaded model.
appendModelName
Appends the model name to the specified field string, if not already present.
public appendModelName(string $field, string|null $modelName = null): string
Parameters:
Parameter | Type | Description |
---|---|---|
$field | string | The field string to append the model name to. |
$modelName | **string | null** |
Return Value:
The modified field string with the model name appended.