Saturday, October 20, 2012

Re: Using function config() fails to define PHP variables

From cake docs:

Config folder:
Holds the (few) configuration files CakePHP uses. Database connection details, bootstrapping, core configuration files and more should be stored here.

So, I think config() is really not meant to be used in Views. If you just need a way of reusing some variables inside views, you should use the solution I described earlier.

Every time you have content (or logic) repeating in many views, you should also consider using a view element or view helper.

That being said, config() function uses "include_once" internally, which means that it will be included only the first time any of these views are rendered. Since the current variable scope is different for each view, calling config('myForms') will fail to load these variables, except the first time you call it.

So, your options are:
  • In AppController::beforeRender() - set the vars with $this->set('myForms', array(...))
  • Make a Helper
  • Make an Element
  • Write/Read it with Configure class

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: