对于正确的CakePHP约定,我将如何存储我将在执行中放在一起的脚本文件?

时间:2023-01-27 11:20:58

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

我正在开发一个小项目,其中CakePHP将输出将由另一个客户端解释的脚本。

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.

到目前为止,我有一个布局设置,正确显示脚本,只有脚本。我只需将其设置为一个数组,每个新行作为数组中的新行。然后视图只是翻过foreach来显示它们,没问题。这很完美。

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.

现在我想做的是将蛋糕切片和骰子放在一起制作不同的预制脚本部分。基本上我会将'methods'存储为某种类型的单个文件,然后可以根据需要由cakephp调用并组合成一个脚本。

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?

我想知道的是:a。如果我遵循蛋糕惯例,这些文本文件应该存储在何处以及如何存储?湾调用这些文件并将它们设置为数组的最简单方法是什么?

Thanks so much!

非常感谢!

1 个解决方案

#1


1  

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)

一个。我将在app / View / Elements /文件夹中创建一个名为Scripts /的文件夹。对于每个单独的脚本,在该文件夹中创建一个文件。例如。 somefunction.ctp。可以通过调用echo $ this-> element('Scripts / somefunction')来打印这些脚本; (省略'.ctp'延伸)

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

湾将这些文件的内容放在一个数组中可能是这样的:

array_push( code_array, $this->element('Scripts/somefunction') );

#1


1  

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)

一个。我将在app / View / Elements /文件夹中创建一个名为Scripts /的文件夹。对于每个单独的脚本,在该文件夹中创建一个文件。例如。 somefunction.ctp。可以通过调用echo $ this-> element('Scripts / somefunction')来打印这些脚本; (省略'.ctp'延伸)

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

湾将这些文件的内容放在一个数组中可能是这样的:

array_push( code_array, $this->element('Scripts/somefunction') );