0

I'm working on a really big project. The aspect I'm currently working on requires that email templates are sent to a user when they're added to a learning course by another user.

The controller that deals with the request, does a bunch of str_replace tasks to find variables in the text (which the user can edit before adding another user to the learning course) and then replaces it with some values in the DB.

I took over this project and I'm not happy with the way half the things are done but time costs dictate I rather just go along with it.

The email is sent using Cake's native email function. It uses a template to capture data and send to the user.

Here's the question:

  1. Should I keep the logic in the controller or do you think it's safe to move it to the element view's .ctp file?

My first instinct is to leave it in the controller as per the usual MVC separation ideals.

Cheers

4

1 回答 1

0

这是一个非常重要的问题 - 您究竟在使用什么来发送电子邮件?旧的电子邮件组件还是新的CakeEmail 类?您使用的是哪个 CakePHP 核心版本?

这里有一些似是而非的方法。你可以:

  1. 设置所有这些变量,将它们传递给视图并在那里进行所有“替换”。
  2. 将此逻辑封装在一个组件中,将其附加到您的控制器并使用它。
  3. 只需将其保留在控制器内的私有函数中,并在需要时调用该函数。(不是真正的 MVC)
于 2013-06-03T15:30:11.363 回答