简体   繁体   English

CakePHP:在视图和元素中嵌入CTP文件名和路径

[英]CakePHP: Embed CTP filename and path in views and elements

I'm looking for an elegant way to make a bit of jquery aware of the filename and path of the ctp file containing a given dom selection. 我正在寻找一种优雅的方法来让jquery知道包含给定dom选择的ctp文件的文件名和路径。 I'm using simple_html_dom to write changes to template flies via an ajax call. 我正在使用simple_html_dom通过ajax调用向模板苍蝇写入更改。 I need to provide the filename and path of the view or element template ctp file that contains the dom element I've selected in order to write changes to the correct file. 我需要提供视图或元素模板ctp文件的文件名和路径,该文件包含我选择的dom元素,以便将更改写入正确的文件。

Outside of manually passing this information into each and every view and element in my application, is there an elegant (and secure) way to make this information available to jquery? 除了手动将此信息传递到我的应用程序中的每个视图和元素之外,是否有一种优雅(且安全)的方法可以将此信息提供给jquery?

Additionally, is there any reason I should be worried about embedding this information in the document in plain text? 另外,我有什么理由担心将这些信息以明文形式嵌入到文档中吗? What is the most appropriate location to store it? 什么是最适合存储的地方? My first thought was in an element's title attribute, but is there a more appropriate location? 我的第一个想法是在元素的title属性中,但是有更合适的位置吗?

Thanks! 谢谢!

UPDATE This question may be better posed as: what is the best way to transparently extend or modify every view and element in cake? 更新这个问题可能更好地提出:透明地扩展或修改蛋糕中的每个视图和元素的最佳方法是什么? I'm passing some information down from app_controler in beforeRender now, but that doesn't allow me to pass information about individual element view files as far as I'm aware. 我现在在beforeRender中从app_controler传递了一些信息,但据我所知,这不允许我传递有关各个元素视图文件的信息。 Ideally, every view and element would look for the presence of a certain classname in dom elements and insert path and filename information in the title attribute for that element before rendering. 理想情况下,每个视图和元素都会在dom元素中查找某个类名的存在,并在呈现之前在该元素的title属性中插入路径和文件名信息。 I can't figure out a good way to do this! 我无法想出一个很好的方法来做到这一点!

<div rel="<?php echo __FILE__; ?>">...</div>

除非我不理解你

You could create your own View class that handled this for you. 您可以创建自己的View类来为您处理此问题。 Inside your 'views' folder, create a file named (for example): custom.php. 在“views”文件夹中,创建一个名为(例如)的文件:custom.php。

This file should contain the class that extends the base View class of CakePHP, named 'CustomView'. 此文件应包含扩展CakePHP的基本View类的类,名为“CustomView”。 Then, in your AppController's beforeFilter, set $this->view = 'Custom'. 然后,在AppController的beforeFilter中,设置$ this-> view ='Custom'。 I'm not sure which method would be best suited to what you want to do, but render() or renderLayout() are probably a good place to start looking. 我不确定哪种方法最适合你想做什么,但render()或renderLayout()可能是一个开始寻找的好地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM