cakephp 避免重复的 .ctp 文件
我的应用程序中的许多模型都是相似的,并且我已经为每个模型的标准 CRUD 自动创建了每个 CTP。换句话说,每个模型的 ctp 文件本身是相同的。我将用于创建表单的字段作为数组传递给助手。我发现虽然我只是在不同的视图目录中一遍又一遍地创建相同的文件。有没有办法可以为每个模型控制器引用 1 add.ctp ?我希望我的问题足够清楚。谢谢。
Many models in my app are similar, and I've automated the creation of each CTP for the standard CRUD for each. In other words, the ctp files themselves for each model are identical. I pass the fields used to create the form as an array to a helper. I find though I'm just creating the same files over and over in separate view directories. Is there a way I can refer to say 1 add.ctp for each of the model controllers? I hope my question is clear enough. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从任何控制器渲染任何视图,因此如果您想创建一个“索引”视图并且其通用性足以让您只需传入 $data,则可以每次渲染相同的视图。
您可以更进一步,在元素文件夹中创建该视图,以将其与控制器完全分离。
http://book.cakephp.org/view/980/render
You can render any view from any controller, so if you want to create one "index" view and its generic enough that you are just passing $data in, you could render the same view each time.
You could take it one step further and create that view in your elements folder to completely detach it from your controllers.
http://book.cakephp.org/view/980/render
https://github.com/infinitas/infinitas/blob/beta/app_controller .php#L389
https://github.com/infinitas/infinitas/blob/beta/app_controller.php#L389