@PoetaWD
Each car has one typeofcar, but each typeofcar has many cars. Therefore, you put typeofcar in Car->has_one, and you put car in TypeOfCar->has_many.
————————————-
@NachoF
Well, it’s not quite that bad. My session method automatically handles returning the error, so it’s just this:
function create_product() {
$this->session->can_create('product');
// continue on
}
I don’t necessarily recommend my technique for someone else. I needed very fine grained controls (for example, a user might be able to view and edit, but not add or delete a specific item), so there’s really no practical way around checking before each controller function. (I also handle other checks, like verifying that the user is logged in, in the controller’s constructor.)
I also use extensions to DataMapper to handle a lot of the more general checks (for example, I have methods that process the results of a form, and do the auth checks internally based on $model). My extended DMZ class also handles the authorization lookups on every get, to prevent users from seeing another user’s data.
You could probably use CodeIgniter’s hooks to handle a more general-purpose authorization technique.