Tips for moving from CB 3 to CB 4?

I’ve been using Coldbox since the v2 days, but I’ve never used it to anywhere near what it’s really capable of. Nevertheless, it’s still my favorite framework by far.

I’m about to start a whole new application, which will end up being very large when complete, and I want to use Coldbox 4. I’ve read the manual on the changes, and it makes some sense, but not a ton. I don’t have a CompSci degree so a lot of this goes over my head.

Has anybody written a blog or HOWTO or something with basics on moving to 4? The more I have to dig into the documentation, the less likely I am to do so. I’ll end up using v3, or just dropping it entirely. :slight_smile:

Silly things like, on v3, I usually commented out the SES stuff for development… if I do that in 4, it throws an error about a BaseHTMLURL or somesuch missing. I know some stuff has changed with injecting dsn stuff, and I know cookie handling has changed too, but I’d have to go back to the docs to try to find that stuff.

What about the basic handler events? Layouts? Can I copy my old Layout.main.cfm file over? You know, stupid stuff like that.

Thanks! :slight_smile:

Rob

Rob,

There are some really good docs and posts on migrating to CB4, but it looks like you’re already in tune with those (I assume you’ve read the compatibility guide: http://wiki.coldbox.org/wiki/Compatibility:4.0.0.cfm ).

  • My first suggestion, since you’re starting your new app from scratch, would be to set your development environment up to as closely match your production environment as possible (e.g. - if you use SES in production, develop with SES enabled). That will make your life easier, as a whole.

  • Second, if you’re concerned about the change, think about installing the compatibility module: box install cbcompat . That will make most of your concerns unecessary, with regard to dealing with changed methods.

  • Third, consider using the CommandBox box coldbox create… namespaces and functions to generate your app files, initially. Some of the generated files contain helpful information on functions and properties that may illuminate some new approaches for you. Start with box coldbox help and drill down in to the namespaces from there.

  • Fourth, just jump in and commit yourself to using and learning CB4. You have the luxury of developing an app from scratch so you don’t have to worry about unexpected errors caused by deprecated or changed methods in your code. I was starting on a new app right, coming off a CB3 app, right as CB4 came out. I didn’t find it difficult, at all, to make the switch (most of the basics are exactly same) and found a lot of cool new things along the way. It’s all in the approach.

HTH,

Jon

P.S. - I don’t have a CS degree either. :slight_smile:

Thanks Jon! I’m gonna go ahead and dive in. I’m not going to install the compatibility module; I’d rather learn the differences early on.

That being said… first issue. I replaced getPlugin(“cookiestorage”) with getInstance(“cookieStorage@cbstorages”) and now I get this error:

# Requested instance not found: ‘cookieStorage@cbstorages’
The instance could not be located in any declared scan location(s) (models) or full path location

It’s installed (via commandbox).

And one more question – what does using commandbox to create the name space do exactly? I.e. what’s the benefit of letting it create app files?

Thanks!!

Rob

Rob, I second Jon’s suggestion just to jump in and do it. I converted a rather old and decent-sized application for a client last night that was using ColdBox 2.6.0 and ColdSpring to ColdBox 4.2 and WireBox. It took several hours and I spent most of them just wading through the string of errors and doing find-replaces to switch out stuff like getPlugin but it really wasn’t that horrible. The app is running great now and I even switched it over to use SES urls.

If you 've read the compat guide that Jon linked to, you SHOULD know everything you need. I’d say 90+% of ColdBox 3 is compatible with 4. Basic stuff like models, views, layouts, and handlers didn’t really change at all.

> Requested instance not found: ‘cookieStorage@cbstorages’

Ensure the module is installed in your modules folder and that you’ve reinitted the framework. If it still doesn’t work, post a stack trace. Chances are you’ve got an interceptor or model init() that’s trying to use it prior to the framework loading modules which is something we can help you work around.

> what does using commandbox to create the name space do exactly?

Well, if you’re creating a new app from scratch, it’s just a nice, quick and easy way to spin up an application template in a format that’s scriptable and doesn’t require any manual steps on your end. If you’re upgrading an old codebase, then the “coldbox create app” stuff isn’t necessary since you already have the app!

> I usually commented out the SES stuff for development.

Why would you do that? If your app uses SES, I’d expect it to use it everywhere.

> it throws an error about a BaseHTMLURL

Probably sesBaseURL. This is a setting created by the SES interceptor when its enabled. I’d have to see the stack trace to see where in your code it was being referenced, but the I think the best answer there is simply not to disable it if your app is using it.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

I suspect your modules weren’t reloaded after you installed the cbstorages module. You should first look at filling out the development() function in your config/Coldbox.cfc file and configure the url. For example, mine usually has modules.autoReload set to true for my development environment (and, someone may disagree but, I put the ormReload() for a framework reinit in the config function so that it fires before Coldbox fully loads):


environments = {
            development = "^*localhost,127.0.0.1"
        };

// Development Environment
    function development(){
        if(structKeyExists(URL,'fwreinit'))
            ormReload();
        //Override Settings
        coldbox.debugmode=false;
        coldbox.handlersIndexAutoReload = true;
        coldbox.handlerCaching = false;
        coldbox.eventCaching = false;
        coldbox.reinitpassword = "";
        coldbox.debugpassword = "";
        wirebox.singletonreload = true;
        modules.autoReload=true;
        //Debugger Settings
        debugger.showRCPanel = false;
        //Custom Settings
        coldbox.customErrorTemplate = "/coldbox/system/includes/BugReport.cfm";
        settings.show_debug="true";
        application.mode=settings.deployment;
    }

As for the rest, I’d suggest running box coldbox create help and then running the help command on all of the subsequent namespaces. For example box coldbox create model MyModel generates two files:

  • /model/MyModel.cfc
  • /tests/specs/integration/MyModelTest.cfc

Both include some comments to get you started. If you want an ORM persistent object, type box coldbox create orm-entity MyEntity and it will generate a persistent Model Entity and the appropriate test, also with comments and examples.

You can quickly scaffold out an application and poke around just doing the above.

My suggestion: give your self a few hours just to “play”! :slight_smile:

Thanks guys!

My cbstorages module is installed in Users/Administrator/Modules, but shouldn’t it be in Users/Administrator/coldbox/modules? I installed it via commandbox. And I did reinit the framework (fwinit=1).

Here’s the whole stack trace:

# Requested instance not found: ‘cookieStorage@cbstorages’
The instance could not be located in any declared scan location(s) (models) or full path location

The error occurred in C:/Users/Administrator/coldbox/system/ioc/Injector.cfc: line 236
Called from C:/Users/Administrator/coldbox/system/FrameworkSupertype.cfc: line 45
Called from C:/inetpub/wwwroot/asde_robg/handlers/main.cfc: line 56
Called from C:/Users/Administrator/coldbox/system/web/Controller.cfc: line 548
Called from C:/Users/Administrator/coldbox/system/web/Controller.cfc: line 425
Called from C:/Users/Administrator/coldbox/system/Bootstrap.cfc: line 74
Called from C:/Users/Administrator/coldbox/system/Bootstrap.cfc: line 107
Called from C:/Users/Administrator/coldbox/system/Bootstrap.cfc: line 350
Called from C:/inetpub/wwwroot/asde_robg/Application.cfc: line 47
|


<br>234 : instance.log.error("Requested instance:#arguments.name# was not located in any declared scan location(s): #structKeyList(instance.binder.getScanLocations())# or full CFC path");<br>235 : throw(message="Requested instance not found: '#arguments.name#'",<br>**236 : detail="The instance could not be located in any declared scan location(s) (#structKeyList(instance.binder.getScanLocations())#) or full path location",**<br>237 : type="Injector.InstanceNotFoundException");<br>238 : }<br>

|

Jon, thanks for the dev env settings, I copied and used those. Q: What’s the settings.deployment for? I ended up putting in deployment = ‘dev’ just so it wouldn’t throw an error.

Oops! You can delete that setting. It’s specific to the application. As a matter of fact, now I’m going to delete that too and remove the calls for it in that app. I just realized the purpose it serves is redundant to other things going on… :slight_smile:

Modules are installed into your application, not into Coldbox’s folder. That said, you can actually install modules at a “global” level into ColdBox, but that’s a different story.

> fwinit=1

It’s ?fwreinit=1

> Here’s the whole stack trace

Actually, that’s just the tag stack, not the stack trace, but from the looks of it your web root is here:
C:/inetpub/wwwroot/

which means your modules should be installed here:
C:/inetpub/wwwroot/modules

Did you run the CommandBox command from the web root?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

AHA! I didn’t know it had to install into the webroot. Okay, that’s fixed. And I typo’d when I wrote fwinit. :wink:

New problem when I reload the site with fwREinit=1…

Event: main.index
Routed URL: N/A
Layout: N/A (Module: )
View: N/A
Timestamp: 08/04/2015 05:00:49 PM

The issue is that data sources are not CFC instances any longer, they are just simple structs.

If you look in the error message you can see if the dependency WireBox box was trying to build was “admin” and one of its constructor arguments is “coldbox:datasource:dsn”.

I assume you have code similar to
myDSN,getName()

Simply change this to
myDNS.name

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

You should try with something like:

getModel( “admin@MYMODULENAME” )

if your model is in a module.

Also check the application.cfc should be:

this.ormSettings = {
cfclocation = [“models”, “modules”],
dialect = “MySQL”,
dbcreate = “update”,
logSQL = false,
flushAtRequestEnd = false,

Thanks Brad! I totally forgot to look in my model cfcs for that. :slight_smile:

Next issue… it’s complaining it can’t find //layouts/Main.cfm. Which is expected since I removed it. Mine is called layout.main.cfm. In CB 3, that was specified in the coldbox.cfc; I don’t see it in there now. Where does that get set?

You guys rock btw! :slight_smile:

That setting hasn’t changed at all to my knowledge. Note, if you used an application skeleton to create one a new app from scratch, it may not contain every possible config item.

layoutSettings = {
defaultLayout = “Layout.Travel.cfm”
};

If in doubt, check the docs here:
http://coldbox.ortusbooks.com/content/configuration/coldboxcfc/configuration_directives/layoutsettings.html

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks! I found that in my coldbox.cfc, but it was empty in both cases. I added layout.main.cfm to both and rwREinit=1’d and while there are no errors, the layout isn’t loading. If I view source, it’s not there. Yet it manages to load the header.cfm, index.cfm and footer.cfm (which I specify in the layout)… yet none of the css or js stuff loads before it. Here’s my layout:

ASDE

#renderView(‘main/header’)#

#renderView()#

#renderView(‘footer’)#

<cfif IsDefined(“rc.message”)>

Am I doing something wrong in that file? Weird.

Thanks again. :slight_smile:

Rob

Try wrapping the contents of your layout in a cfoutput. It’s probably related to an “enableCFoutputOnly” somewhere.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

BINGO! I should have thought of that. :slight_smile:

Thanks!

No problem. I’ve done this a few times, so I’m used to the common things that crop up :slight_smile:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Found an other one… this one’s SES related I think.

So, the first page that loads is main.index. This works fine.

On my little nav bar, I have, for example:

  • Home
  • About
  • Contact
  • Login
  • If you over over it, you see http://mytestsite/index.cfm/main/index

    And if you click on it, I get a 404. First, why is “index.cfm” showing up in there, and second, why is it failing? This is one of the things I dislike about the SES stuff. I go through this crap with Mura and end up having to install weird rewrite crap in IIS to make it work.

    Try to edit your config/routes.cfm and remove index.cfm, you should have something like this:

    `

    if( len(getSetting(‘AppMapping’) ) lte 1){
    setBaseURL(“http://#cgi.HTTP_HOST#/”);
    }
    else{
    setBaseURL(“http://#cgi.HTTP_HOST#/#getSetting(‘AppMapping’)#/”);
    }

    `

    Also if you are using commandbox enable the url rewrites

    server start --rewritesEnable

    Thanks, did that and it got rid of the index.cfm in the url, but still 404’ing when I click the links. I do have commandbox installed, but I’m building this on their production server as a separate site… it’s CF11 with IIS. Will that --rewritesEnable still work?