Hi, You could consider this:
Create a folder in your /app dir, e.g. /app/mylibs. Put your global classes / utils there, e.g. translator.php, global_utils.php Next create a helper file, e.g. mybasics.php, with some code like that: <code> function uses_mylib() { $args = func_get_args(); foreach ($args as $arg) { if (file_exists(APP . 'mylib' . DS . $arg . '.php')) { require_once(APP . 'mylib' . DS . $arg . '.php'); } else { } } } </code> and place it under /app/mybasics.php. Include this file above the class definition of your app/app_controller.php, like so: <code> require_once (APP . DS . 'mybasics.php'); </code> to make sure the function uses_mylib is available everywhere. >From your views, helpers, controllers, components etc. you can now just do: <code> uses_mylib('translator', 'global_utils'); </code> and the corresponding files will be required thus making their functionality ready to use. This is similar to cakes uses function in /cake/basics.php. Cheers, JP On Jan 21, 3:54 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Ok, I have never regarded the vendors directory as a place to put my > code. I have viewed it exclusively as a place for "external" libraries > and PEAR stuff if needed. > > Your suggestion should work since neithercomponentnorhelperuses > any cake functionality. They simply determine the current language and > lookup and return the labels when they are requested. > > I'd better explain what I mean by problems using thehelperfor > flashes. The following is what a normal setFlash looks liek now: > > $this->Session->setFlash( $this->Lang->show('save_ok') ); > or for a flash using dynamic data: > $this->Session->setFlash( sprintf( $this->Lang->show('save_ok'), 'some > value', $this->Model->id) ); > > To use thehelperin a flash-layout I would have to write something > like: > > $this->Session->setFlash( $this->Lang->show('save_ok'), > 'my_layout') ); > not too bad but with a sprinted one: > $this->Session->setFlash( $this->Lang->show('save_ok'), 'my_layout', > array('args' =>array('some value',$this->Model->id)) ); > > And the flash-layout will have to take the values for sprintf() and > pass them along. Since they can be one, two or more I have to make use > of some php-feature I can't remember now to turn the array into > arguments for the function. IMHO not a lot of fun :) I'd rather not go > down this route. > > I hope that explains why I want to avoid making the setFlash more > complex and put a lot of login in the flash-layout that really has > nothing to do with flashing messages. To me taking "User %s was saved" > and turning it into "User Martin was saved" does not belong in a > layout. I have it in my controllers now but plan to more the whole > thing into the languagecomponent/helper. > > thanks for your suggestion regarding the vendors dir. > > On Jan 21, 3:25 pm, nate <[EMAIL PROTECTED]> wrote: > > > The simplest way to do it would be to write a base class, stick it in > > your vendors, and have thehelperandcomponenteach extend it. This > > is kind of cheating, but as long as yourhelperdoesn't need any of > > theHelperbase class functionality, you should be good. > > > As far as the setFlash bit, Im not 100% sure what you mean, but > > sending your variables down to a custom flash layout should not result > > in messy code by any means, unless I'm not understanding your > > requirements here. > > > On Jan 21, 8:07 am, "[EMAIL PROTECTED]" > > > <[EMAIL PROTECTED]> wrote: > > > OMG! I'm so sorry for the language in the top paragraph. > > > Try this instead :) > > > > "I am being picky about trying to keep things DRY and I would really > > > like be able to have acomponentand ahelperuse the same code." On Jan 21, 3:54 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Ok, I have never regarded the vendors directory as a place to put my > code. I have viewed it exclusively as a place for "external" libraries > and PEAR stuff if needed. > > Your suggestion should work since neithercomponentnorhelperuses > any cake functionality. They simply determine the current language and > lookup and return the labels when they are requested. > > I'd better explain what I mean by problems using thehelperfor > flashes. The following is what a normal setFlash looks liek now: > > $this->Session->setFlash( $this->Lang->show('save_ok') ); > or for a flash using dynamic data: > $this->Session->setFlash( sprintf( $this->Lang->show('save_ok'), 'some > value', $this->Model->id) ); > > To use thehelperin a flash-layout I would have to write something > like: > > $this->Session->setFlash( $this->Lang->show('save_ok'), > 'my_layout') ); > not too bad but with a sprinted one: > $this->Session->setFlash( $this->Lang->show('save_ok'), 'my_layout', > array('args' =>array('some value',$this->Model->id)) ); > > And the flash-layout will have to take the values for sprintf() and > pass them along. Since they can be one, two or more I have to make use > of some php-feature I can't remember now to turn the array into > arguments for the function. IMHO not a lot of fun :) I'd rather not go > down this route. > > I hope that explains why I want to avoid making the setFlash more > complex and put a lot of login in the flash-layout that really has > nothing to do with flashing messages. To me taking "User %s was saved" > and turning it into "User Martin was saved" does not belong in a > layout. I have it in my controllers now but plan to more the whole > thing into the languagecomponent/helper. > > thanks for your suggestion regarding the vendors dir. > > On Jan 21, 3:25 pm, nate <[EMAIL PROTECTED]> wrote: > > > The simplest way to do it would be to write a base class, stick it in > > your vendors, and have thehelperandcomponenteach extend it. This > > is kind of cheating, but as long as yourhelperdoesn't need any of > > theHelperbase class functionality, you should be good. > > > As far as the setFlash bit, Im not 100% sure what you mean, but > > sending your variables down to a custom flash layout should not result > > in messy code by any means, unless I'm not understanding your > > requirements here. > > > On Jan 21, 8:07 am, "[EMAIL PROTECTED]" > > > <[EMAIL PROTECTED]> wrote: > > > OMG! I'm so sorry for the language in the top paragraph. > > > Try this instead :) > > > > "I am being picky about trying to keep things DRY and I would really > > > like be able to have acomponentand ahelperuse the same code." --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---