Question on routes

8 views
Skip to first unread message

Dan Vega

unread,
Sep 13, 2011, 10:04:59 AM9/13/11
to col...@googlegroups.com
I setup a route that looks like this

<cfset add("/category/edit/:category_id",{
defaults = {
controller = "category",
action = "edit"
}
})>

but when I visit /public/index.cfm/category/edit/9

I was expecting url.category_id to equal 9 instead it does not even exist. What am I missing here? 

Tony Nelson

unread,
Sep 13, 2011, 12:24:11 PM9/13/11
to col...@googlegroups.com
Does it exist in the params scope?


-Tony

Dan Vega

unread,
Sep 13, 2011, 12:29:34 PM9/13/11
to col...@googlegroups.com
duh / yes it does, sorry! Ok I updated my example but now when I save I am getting an error 

public void function save(){
var category = _Category.get( params.category_id );
category.setName(params.name);
category.setSort(params.sort);
var result = validationService.validate(category);

if( !result.hasErrors() ){
category.save();
  flash.success = "Category Saved!";
        redirect({action="list"});
} else {
// preserve some data on redirect
flash.errors = result.getErrorMessages();
flash.category = category;
redirect({action="edit"});
}

}


Variable DAO is undefined.

 
The error occurred in C:\www\coldmvc\Model.cfc: line 173
Called fromC:\www\hyrule\samples\frameworks\coldmvc\app\controllers\CategoryController.cfc: line 26
Called from : line 1
Called from C:\www\coldmvc\app\util\RouteDispatcher.cfc: line 299
Called from C:\www\coldmvc\app\util\RouteDispatcher.cfc: line 268
Called from C:\www\coldmvc\app\util\RouteDispatcher.cfc: line 72
Called from : line 1
Called from C:\www\coldmvc\app\util\EventDispatcher.cfc: line 114
Called from C:\www\coldmvc\index.cfm: line 2
Called from C:\www\hyrule\samples\frameworks\coldmvc\public\index.cfm: line 1
171 : 	public any function save(boolean flush="true") {
172 : 
173 : 		return DAO.save(this, arguments.flush);
174 : 
175 : 	}

Tony Nelson

unread,
Sep 13, 2011, 12:35:23 PM9/13/11
to col...@googlegroups.com
It looks like the DAO isn't being autowired into the model. Can you try calling category.getDAO() and seeing if it exists or not?


-Tony

Dan Vega

unread,
Sep 13, 2011, 12:39:42 PM9/13/11
to col...@googlegroups.com
it comes up as undefined 

Tony Nelson

unread,
Sep 13, 2011, 12:40:59 PM9/13/11
to col...@googlegroups.com
Is the DAO listed inside the Beans section of the ColdMVC debug information?


-Tony

Dan Vega

unread,
Sep 13, 2011, 12:47:45 PM9/13/11
to col...@googlegroups.com
9-13-2011 12-46-51 PM.png

Tony Nelson

unread,
Sep 13, 2011, 12:57:29 PM9/13/11
to col...@googlegroups.com
Can you create a pastebin of your Application.cfc, CategoryController.cfc, and Category.cfc? Are you running the latest version of CF?


-Tony

Dan Vega

unread,
Sep 13, 2011, 1:00:19 PM9/13/11
to col...@googlegroups.com

Tony Nelson

unread,
Sep 13, 2011, 1:27:17 PM9/13/11
to col...@googlegroups.com
It looks like the DAO isn't being autowired into the Category model because the ColdMVC ORM event handler isn't specified inside your Application.cfc.

You should be able to leave your Application.cfc empty and it should still work as expected using the default settings.

If you don't want to use an empty Application.cfc, you could specify this.ormSettings.eventHandler = "coldmvc.app.util.EventHandler" and it should start working. However, I would just recommend using an empty Application.cfc. Most of the ORM settings are available via config settings if you need to customize a setting.

-Tony

Dan Vega

unread,
Sep 13, 2011, 1:44:29 PM9/13/11
to col...@googlegroups.com
ok that was it... i don't see these variables in the docs. Are you saying I can setup all of my orm settings in the config ini? 

Tony Nelson

unread,
Sep 13, 2011, 1:49:26 PM9/13/11
to col...@googlegroups.com
Yeah they're not in the docs yet. Right now you can set the following ORM settings inside the config.ini.
  • ormDialect
  • ormDBCreate
  • ormLogSQL
  • ormSaveMapping

I was thinking about changing the config.ini to better handle the Application.cfc settings rather than rely on magic keywords, but I haven't figured out the best approach yet. Maybe I'll end up keying off a "this" struct or something like this:

[defaults]
this.ormEnabled = true
this.ormSettings.logSQL = true
this.ormSettings.eventHander = coldmvc.app.util.EventHandler


-Tony

Tony Nelson

unread,
Sep 14, 2011, 9:06:59 AM9/14/11
to ColdMVC
I pushed an update last night to allow you to define Application.cfc
settings inside the config.ini using a "this" struct. Now, instead of
having "ormLogSQL = true" inside your config.ini, you can add
"this.ormSettings.logSQL = true" and it will copy the config settings
into the Application.cfc's "this" scope.

On Sep 13, 12:49 pm, Tony Nelson <tonynelso...@gmail.com> wrote:
> Yeah they're not in the docs yet. Right now you can set the following ORM
> settings inside the config.ini.
>
>    - ormDialect
>    - ormDBCreate
>    - ormLogSQL
>    - ormSaveMapping
>
> I was thinking about changing the config.ini to better handle the
> Application.cfc settings rather than rely on magic keywords, but I haven't
> figured out the best approach yet. Maybe I'll end up keying off a "this"
> struct or something like this:
>
> [defaults]
> this.ormEnabled = true
> this.ormSettings.logSQL = true
> this.ormSettings.eventHander = coldmvc.app.util.EventHandler
>
> -Tony
>
>
>
>
>
>
>
> On Tue, Sep 13, 2011 at 12:44 PM, Dan Vega <danv...@gmail.com> wrote:
> > ok that was it... i don't see these variables in the docs. Are you saying I
> > can setup all of my orm settings in the config ini?
>
> > Thank You
> > Dan Vega
> > danv...@gmail.com
> >http://www.danvega.org/
>
> > On Tue, Sep 13, 2011 at 1:27 PM, Tony Nelson <tonynelso...@gmail.com>wrote:
>
> >> It looks like the DAO isn't being autowired into the Category model
> >> because the ColdMVC ORM event handler isn't specified inside your
> >> Application.cfc.
>
> >> You should be able to leave your Application.cfc empty and it should still
> >> work as expected using the default settings.
>
> >> If you don't want to use an empty Application.cfc, you could specify
> >> this.ormSettings.eventHandler = "coldmvc.app.util.EventHandler" and it
> >> should start working. However, I would just recommend using an empty
> >> Application.cfc. Most of the ORM settings are available via config settings
> >> if you need to customize a setting.
>
> >> -Tony
>
> >> On Tue, Sep 13, 2011 at 12:00 PM, Dan Vega <danv...@gmail.com> wrote:
>
> >>>http://pastebin.com/7ZqEZ980
> >>>http://pastebin.com/ssF2cT2e
> >>>http://pastebin.com/B6VUXMse
>
> >>> Yes - running 9.0.1
>
> >>> Thank You
> >>> Dan Vega
> >>> danv...@gmail.com
> >>>http://www.danvega.org/
>
> >>> On Tue, Sep 13, 2011 at 12:57 PM, Tony Nelson <tonynelso...@gmail.com>wrote:
>
> >>>> Can you create a pastebin of your Application.cfc,
> >>>> CategoryController.cfc, and Category.cfc? Are you running the latest version
> >>>> of CF?
>
> >>>> -Tony
>
> >>>> On Tue, Sep 13, 2011 at 11:47 AM, Dan Vega <danv...@gmail.com> wrote:
>
> >>>>> Thank You
> >>>>> Dan Vega
> >>>>> danv...@gmail.com
> >>>>>http://www.danvega.org/
>
> >>>>> On Tue, Sep 13, 2011 at 12:40 PM, Tony Nelson <tonynelso...@gmail.com>wrote:
>
> >>>>>> Is the DAO listed inside the Beans section of the ColdMVC debug
> >>>>>> information?
>
> >>>>>> -Tony
>
> >>>>>> On Tue, Sep 13, 2011 at 11:39 AM, Dan Vega <danv...@gmail.com> wrote:
>
> >>>>>>> it comes up as undefined
>
> >>>>>>> Thank You
> >>>>>>> Dan Vega
> >>>>>>> danv...@gmail.com
> >>>>>>>http://www.danvega.org/
>
> >>>>>>> On Tue, Sep 13, 2011 at 12:35 PM, Tony Nelson <
> >>>>>>> tonynelso...@gmail.com> wrote:
>
> >>>>>>>> It looks like the DAO isn't being autowired into the model. Can you
> >>>>>>>> try calling category.getDAO() and seeing if it exists or not?
>
> >>>>>>>> -Tony
>
> >>>>>>>> On Tue, Sep 13, 2011 at 11:29 AM, Dan Vega <danv...@gmail.com>wrote:
>
> >>>>>>>>> duh / yes it does, sorry! Ok I updated my example but now when I
> >>>>>>>>> save I am getting an error
>
> >>>>>>>>> public void function save(){
> >>>>>>>>>  var category = _Category.get( params.category_id );
> >>>>>>>>> category.setName(params.name);
> >>>>>>>>>  category.setSort(params.sort);
> >>>>>>>>>  var result = validationService.validate(category);
>
> >>>>>>>>> if( !result.hasErrors() ){
> >>>>>>>>> category.save();
> >>>>>>>>>   flash.success = "Category Saved!";
> >>>>>>>>>         redirect({action="list"});
> >>>>>>>>> } else {
> >>>>>>>>> // preserve some data on redirect
> >>>>>>>>>  flash.errors = result.getErrorMessages();
> >>>>>>>>> flash.category = category;
> >>>>>>>>> redirect({action="edit"});
> >>>>>>>>>  }
>
> >>>>>>>>> }
>
> >>>>>>>>> Variable DAO is undefined.  The error occurred in *C:\www\coldmvc\Model.cfc:
> >>>>>>>>> line 173*
> >>>>>>>>> *Called from*C:\www\hyrule\samples\frameworks\coldmvc\app\controllers\CategoryController.cfc:
> >>>>>>>>> line 26
> >>>>>>>>> *Called from* : line 1
> >>>>>>>>> *Called from* C:\www\coldmvc\app\util\RouteDispatcher.cfc: line
> >>>>>>>>> 299
> >>>>>>>>> *Called from* C:\www\coldmvc\app\util\RouteDispatcher.cfc: line
> >>>>>>>>> 268
> >>>>>>>>> *Called from* C:\www\coldmvc\app\util\RouteDispatcher.cfc: line 72
> >>>>>>>>> *Called from* : line 1
> >>>>>>>>> *Called from* C:\www\coldmvc\app\util\EventDispatcher.cfc: line
> >>>>>>>>> 114
> >>>>>>>>> *Called from* C:\www\coldmvc\index.cfm: line 2
> >>>>>>>>> *Called from* C:\www\hyrule\samples\frameworks\coldmvc\public\index.cfm:
> >>>>>>>>> line 1
>
> >>>>>>>>> 171 :      public any function save(boolean flush="true") {
> >>>>>>>>> 172 : *173 :               return DAO.save(this, arguments.flush);*
> >>>>>>>>> 174 :
> >>>>>>>>> 175 :      }
>
> >>>>>>>>> Thank You
>
> >>>>>>>>> Dan Vega
> >>>>>>>>> danv...@gmail.com
> >>>>>>>>>http://www.danvega.org/
>
> >>>>>>>>> On Tue, Sep 13, 2011 at 12:24 PM, Tony Nelson <
> >>>>>>>>> tonynelso...@gmail.com> wrote:
>
> >>>>>>>>>> Does it exist in the params scope?
>
> >>>>>>>>>> -Tony
>
Reply all
Reply to author
Forward
0 new messages