[eluser]drshields[/eluser]
This is a general question relating to MVC development.
I want to add a value to a database if the value doesn't currently exist, and then return the insert id of that entry. If the value already exists, just return the id of that entry.
Do I do the logic piece of that in the controller, or in the model? Doing the controller requires two functions, where doing it in the model requires only one.
EXAMPLE
From the controller, I call one function to see if it exists, and another to add it if it doesn't exist:
Code:
if ($this->database_model->value_exists($some_value) == NULL)
{
$new_id = $this->database_model->add_value($something);
}
Now if I put the logic in the model, my controller looks like this:
Code:
$value_id = get_value($something);
In my model:
Code:
function get_value($something)
{
// do query to get value. if it exists, return the id
// if value doesn't exist, insert $something and return id
}
What is the "proper" way to do this? Does it matter?