Skip to content

Instantly share code, notes, and snippets.

@neokoenig
Created March 15, 2017 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neokoenig/a136cecef508506503fa5a026a2fc782 to your computer and use it in GitHub Desktop.
Save neokoenig/a136cecef508506503fa5a026a2fc782 to your computer and use it in GitHub Desktop.
// In controller.cfc
function getStuff(){
myStuff=model("foo").findAll(order="name");
}
// Mycontroller.cfc
init(){
filters(through="getStuff", only="index");
}
index(){
// Index now has access to myStuff
}
// /views/mycontroller/index.cfm
#select(objectname="myObject", options=myStuff)#
@chrisdpeters
Copy link

Make sure it's private function getStuff()

@QuillDesign
Copy link

So I did exactly what you've suggested and I am then on the index view page and it is just showing function definition dump (you know that brown box) the one that says arguments none, returntype any etc,

@QuillDesign
Copy link

its' not returning a query result

@QuillDesign
Copy link

// Controller.cfc
private function getCountries() {
qCountry = model("countries").findAll(select="countryA2,name", where="active = 1");
}

// Addresses.cfc
public void function init() {
super.init();
filters(through="isAuthenticated,isAuthorized");
filters(through="$findAddress", only="show,edit,delete");
filters(through="getCountries", only="edit,new");

}

My /addresses/new.cfm

2017-03-15_1457

@neokoenig
Copy link
Author

Are you dumping getCountries() or qCountry?

@QuillDesign
Copy link

I have dumped getCountries / getCountries() and just tried qCountry and that is what I needed ... mercy ok that sheds a bit of light on some things.

Thank you.

@QuillDesign
Copy link

So another question with this one (sorry to drag this back up ... but I'm struggling).

IF I want call the query "mystuff" to run on EVERY page ...do I have to add the filter to EVERY controller? or is there a better way.
 

@QuillDesign
Copy link

QuillDesign commented Jul 10, 2017

I may have just figured it out ... if I put filters(through="getStuff") in the controller.cfc then it seems to fire for EVERYWHERE. but I guess I am still going to say - is this the correct way to do this?

Specifically if this is being called in the "layout" and will pull a category list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment