Coldbox access in model folder

Hi folks,

How to use event.setView in model folder.

I’m calling modules(modules/users/model/register/registerSVC.cfc) folder from main handler

In registerSVC.cfc I’m using using event.setView(‘users/register/register.cfm’);

When I run this code I’m getting EVENT is not defined in Variables.

Please suggest me.

Thanks in advance.

I think your again confused about the role of your models in an MVC application. The rules for what variables you have in a model is similar to what functions you have:

  • Did you define the variable yourself in that CFC?
  • Did you define the variable yourself in a superclass?
  • Is there a property of that name defined in the CFC?
  • Is there a WireBox mapping set up to inject a property of that name in this CFC?
    If the answer is no, (or I don’t know) to all of those questions, then that variable doesn’t exist :slight_smile:

The “event” object (also known as the request context) is available in your handlers, views, layouts, etc, but is not part of your models. Now, there are ways to get it, but most of them are a bad idea ™. Namely because your model should not be concerning itself with the views that are being set-- that is an excellent job for your handlers to do. If logic inside of the model affects what view to display, I would recommend building your model’s API in such a way that it returns the necessary information for the handler to set the appropriate view.



ColdBox Platform Evangelist
Ortus Solutions, Corp

ColdBox Platform:

I suggest you read up on what MVC stands for and then learn to apply that to your Application.