For proper CakePHP conventions, how would I go about storing pieces of a script file that I would put together in execution?

StackOverflow https://stackoverflow.com//questions/11702597

  •  13-12-2019
  •  | 
  •  

Question

I'm working on a little project in which CakePHP will be outputting script which will be interpreted by another client.

Thus far I have a layout setup which properly displays the script and only the script. I simply set it into an array, which each new line as a new row in the array. The view then just rolls through a foreach to display them, no problem. This is working perfectly.

Now what I would like to do is have cake slice and dice different pre-made script portions together. Basically I would store 'methods' as individual files of some kind, which can then be called by cakephp as needed and put together to make a single script.

What I'm wondering is:
a. If I'm following the cake conventions, where and how should these text files be stored?
b. What's the easiest way to call these files and set them into an array?

Thanks so much!

Was it helpful?

Solution

a.
I woud create a folder named Scripts/ in the app/View/Elements/ folder.
For each individual script, create a file in that folder. E.g. somefunction.ctp.
Those scripts can than be printed by calling echo $this->element('Scripts/somefunction'); (omit the '.ctp' extention)

b.
Putting the content of these files in an array could go like this:

array_push( code_array, $this->element('Scripts/somefunction') );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top