Re: Global data
Global variables in general are the spawn of satan. However both constants and using Configure::write('var', $value) are excellent replacements as they prevent the collisions and spaghetti code that globals can help create. http://book.cakephp.org/view/39/configuration -Mark --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Global data
Hey, You can use the Configure class of cakephp to store your settings in configuration files like cake do for storing its configurations('config/database.php' , 'config/core.php' etc..). See the api for the class (located at 'cake/libs/configure.php')for more details regards, Sudhir RJ wrote: > In my project , i want some data to be available globally i.e > informations like smtp-host,application name and several configuration > settings so that i don't have to hard-code it in my program but > directly read from the global variable.This would help me when i > deploy it on client side, i'll just change the global variables and it > would reflect in my application. > How to achieve the same in cakephp > > Thanks, > RJ > > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Global data
Your best bet is to probably set a constant in the bootstrap.php file. On Jul 15, 11:39 pm, RJ <[EMAIL PROTECTED]> wrote: > In my project , i want some data to be available globally i.e > informations like smtp-host,application name and several configuration > settings so that i don't have to hard-code it in my program but > directly read from the global variable.This would help me when i > deploy it on client side, i'll just change the global variables and it > would reflect in my application. > How to achieve the same in cakephp > > Thanks, > RJ --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Global data
In my project , i want some data to be available globally i.e informations like smtp-host,application name and several configuration settings so that i don't have to hard-code it in my program but directly read from the global variable.This would help me when i deploy it on client side, i'll just change the global variables and it would reflect in my application. How to achieve the same in cakephp Thanks, RJ --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Global data
Just use the beforeRender() method at AppControler, which should be the base of your controllers. So for example you have app_controller.php on your app/ directory: class AppController extends Controller { function beforeRender() { $data = array ( 'message' => 'Hello World!'; ); $this->set('data', $data); } } Then you have your controllers extend AppController. For example, you can have app/controllers/test_controller.php: class TestController extends AppController { function index() { // Do nothing } } And also app/controllers/another_test_controller.php: class AnotherTestController extends AppController { function index() { $this->set('extra', 'Extra Message'); } } Then the app/views/test/index.thtml: And the message is: And the app/views/another_test/index.thtml: And the message is: with some extra message: Remember the MVC separation logic. Data should be passed on TO the view, and the view SHOULD NOT fetch data by itself. -MI --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Global data
Quite often I need to display data that's common to a lot of views - for example, when dealing with a user that's linked to an organisation, to display the organisation that the user belongs to on every page they see. It seems obtuse to have to call $this->User->Find... in every function in every controller. Outside Cake, I'd usually stick the organisation in the session to save lookups and provide easy access, but I've not found a way of accessing a session value from a view without having to call set() in every function, which is almost as bad. I suspect there is some simple 'Cakeish' way of sharing data between views, and across different controllers, but I've not found it as yet. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---