Re: Include PHP code in view
> Okay, sounds good. So where do I find this information on building my > own helper? Please provide a link to some instructions if you can. A helper is definitely what you want here. They are really easy: http://manual.cakephp.org/chapter/helpers (Section 2, all the way at the bottom) Basically you create a file in the helpers directory called common.php and then inside it define your class: Now in your view you can call your function like myFunc($data); ?>. Just make sure you include the helper inside your controller or AppController. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Include PHP code in view
Okay, sounds good. So where do I find this information on building my own helper? Please provide a link to some instructions if you can. Thanks. P- On Mar 26, 5:24 pm, "Samuel DeVore" <[EMAIL PROTECTED]> wrote: > On Wed, Mar 26, 2008 at 3:15 PM, CodeHooligans <[EMAIL PROTECTED]> wrote: > > As for the comment on the no business logic in the View I agree. But > > then again I never actually stated what this function I'm including > > does. It's not business logic. It's just code to help build the radio > > buttons sets since each form (a Questionnaire) has 80+ questions. It's > > similar to the built-in Cake function for building say an input field. > > But for my case I need to wrap some HTML code around each question and > > Yes/No radio button set. It's easier to place this into a function to > > build the view output then manually for each of the questions. > > Sounds to me like you should make a helper for yourself to contain > these kinds of functions... > > -- > -- > (the old fart) the advice is free, the lack of crankiness will cost you > > - its a fine line between a real question and an idiot > > http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/http://blog.samdevore.com/cakephp-pages/my-cake-wont-bake/http://blog.samdevore.com/cakephp-pages/i-cant-bake/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Include PHP code in view
On Wed, Mar 26, 2008 at 3:15 PM, CodeHooligans <[EMAIL PROTECTED]> wrote: > As for the comment on the no business logic in the View I agree. But > then again I never actually stated what this function I'm including > does. It's not business logic. It's just code to help build the radio > buttons sets since each form (a Questionnaire) has 80+ questions. It's > similar to the built-in Cake function for building say an input field. > But for my case I need to wrap some HTML code around each question and > Yes/No radio button set. It's easier to place this into a function to > build the view output then manually for each of the questions. Sounds to me like you should make a helper for yourself to contain these kinds of functions... -- -- (the old fart) the advice is free, the lack of crankiness will cost you - its a fine line between a real question and an idiot http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/ http://blog.samdevore.com/cakephp-pages/my-cake-wont-bake/ http://blog.samdevore.com/cakephp-pages/i-cant-bake/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Include PHP code in view
Thanks for the reply Joel. As usual just after I posted this tried something else and got this working. I was placing the 'vendor();' call at the bottom of the index.thtml file. As I replaced the original function with it. I've found if I place the vendor() call before the function is needed it works fine. Strange PHP. As for the comment on the no business logic in the View I agree. But then again I never actually stated what this function I'm including does. It's not business logic. It's just code to help build the radio buttons sets since each form (a Questionnaire) has 80+ questions. It's similar to the built-in Cake function for building say an input field. But for my case I need to wrap some HTML code around each question and Yes/No radio button set. It's easier to place this into a function to build the view output then manually for each of the questions. P- On Mar 26, 4:56 pm, Joel <[EMAIL PROTECTED]> wrote: > You can paste some code into bootstrap.php, which then makes your > function available everywhere. You should never include business/ > controller logic into a view; that's just bad practice. > > Well, putting code in the bootstrap.php file is also not very MVC- > pattern compliant, but sometimes you gotta do whatcha gotta do. > > -J. > > On Mar 26, 5:20 pm, CodeHooligans <[EMAIL PROTECTED]> wrote: > > > Hello all, > > > I'm having a but of an issue. I have two forms. But are simple and > > submit to discrete backend controllers. Both have their own set of > > views (add, edit, index). Each submit into respective tables in the > > database. I'm running cake 1.1.xxx (The current stable release). > > > So here is my issue. I'm try to just include a common function that is > > used in each of the index.thtml files. I've tried a traditional PHP > > include. Placed the php file under the site root and tried including > > the path and filename. Something I would do under a normal PHP > > environment. > > > The included file will load without issues. Meaning if I use require() > > no error is reported. The problem is the function that is inside the > > included file is not loaded. > > > I've read through the other message and have tried the app/vendors and > > calling the include file via vendor('filename'); without much luck. > > > What am I missing here? The function runs fine when I place it > > directly into the index.thtml files(s). My problem is I really don't > > want to have this in 2 different places. It's the same code. Also I > > would put this in the controller but again it would need to be in both > > controllers. Does not seem efficient to me. > > > P- --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Include PHP code in view
You can paste some code into bootstrap.php, which then makes your function available everywhere. You should never include business/ controller logic into a view; that's just bad practice. Well, putting code in the bootstrap.php file is also not very MVC- pattern compliant, but sometimes you gotta do whatcha gotta do. -J. On Mar 26, 5:20 pm, CodeHooligans <[EMAIL PROTECTED]> wrote: > Hello all, > > I'm having a but of an issue. I have two forms. But are simple and > submit to discrete backend controllers. Both have their own set of > views (add, edit, index). Each submit into respective tables in the > database. I'm running cake 1.1.xxx (The current stable release). > > So here is my issue. I'm try to just include a common function that is > used in each of the index.thtml files. I've tried a traditional PHP > include. Placed the php file under the site root and tried including > the path and filename. Something I would do under a normal PHP > environment. > > The included file will load without issues. Meaning if I use require() > no error is reported. The problem is the function that is inside the > included file is not loaded. > > I've read through the other message and have tried the app/vendors and > calling the include file via vendor('filename'); without much luck. > > What am I missing here? The function runs fine when I place it > directly into the index.thtml files(s). My problem is I really don't > want to have this in 2 different places. It's the same code. Also I > would put this in the controller but again it would need to be in both > controllers. Does not seem efficient to me. > > P- --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Include PHP code in view
Hello all, I'm having a but of an issue. I have two forms. But are simple and submit to discrete backend controllers. Both have their own set of views (add, edit, index). Each submit into respective tables in the database. I'm running cake 1.1.xxx (The current stable release). So here is my issue. I'm try to just include a common function that is used in each of the index.thtml files. I've tried a traditional PHP include. Placed the php file under the site root and tried including the path and filename. Something I would do under a normal PHP environment. The included file will load without issues. Meaning if I use require() no error is reported. The problem is the function that is inside the included file is not loaded. I've read through the other message and have tried the app/vendors and calling the include file via vendor('filename'); without much luck. What am I missing here? The function runs fine when I place it directly into the index.thtml files(s). My problem is I really don't want to have this in 2 different places. It's the same code. Also I would put this in the controller but again it would need to be in both controllers. Does not seem efficient to me. P- --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---