HTML5/js/PHP/CSS 中是否有标准的编程方式来创建可重用对象?
Is there a standard way of programming in HTML5/js/PHP/CSS to create reusable objects?
我(在空闲时间)创建了一个 html 页面,该页面使用 PHP 创建我的动态对象。
此页面调用我的 javascript 以接收来自 AJAX 用户的输入。
我的对象使用 AJAX 作为输入(PHP 执行 $_GET),然后我的对象将打开到我的 PDO mySQL 数据库的连接,执行查询并接收详细信息。它显示了我的对象和回声 HTML5 的细节,我使用 CSS 来做一些不错的功能。
它工作正常。我学到了很多(CSS 很棒),但是与其他编程语言相比,这在学习上非常相似,但又非常不同!
我发现它的不同之处在于...对于我想做的任何事情,总是有 许多 不同的方法来做。由于这是一组共同发挥作用的语言(PHP、javascript、CSS3 和 HTML5)。
目前我以某种方式避免了 jQuery,因为我正在学习并且更喜欢以困难的方式做所有事情。但是我注意到很多这样的插件,例如条形图,都是在 javascript 中创建的,并以数组的形式在那里提供数据。
现在我想要第二个页面,它的功能与第一个页面相同,但访问不同的数据并可能执行不同的操作,但它的显示效果非常相似。
所以我希望能够再次使用我的对象,只是给它不同的参数、不同的输入等等……就好像我刚刚使用了一个插件一样。所以现在我正在考虑在 js 中实例化它并从那里输入数据。
我只是想要一些好的指导,因为我刚开始,我学得越多,它就变得越广泛:)
这就是我的问题所在:
问:HTML5/js/PHP/CSS 中是否有标准的编程方式来创建可重用对象?
欢迎参考和 expertise/experience,我不想开始辩论。我想遵循一个标准。
我不是真的 100% 确定你在问什么 - 我从你的措辞中猜测你是一个编程新手。
为了回答你的问题(某种程度上),最接近 Javascript、PHP 和(不是真的)HTML 和 CSS 之间的公共接口的东西将是 JSON,或 Javascript 对象表示法。 PHP 有库可以读取 JSON,而 JavaScript 可以本地读取它(使用 jQuery 更好)。一些数据库(CouchDB,在某种程度上,MongoDB、Neo4j 等)甚至会几乎逐字地存储您的 JSON。
在任何情况下,存储数据的方式都应该在数据库中进行,并且 JSON,无论使用何种数据库,通常都被认为是在前端和后端之间进行通信的最佳方式代码(顺便说一下,它明确区分了 HTML/CSS/JS 和 PHP)。
不清楚你到底在问什么,但这是我对我的理解的回答。
服务器端组织:
如果您要创建一个大项目,我强烈建议您使用 PHP framework
(symphony, codeigniter 等),如果您不这样做,请考虑以下内容:
1.遵循 MVC 结构
MVC 结构可以用多种不同的方式表示。但是,为简单起见,您可以通过创建 3 个文件夹(controller、model、view)来完成此操作。
每个文件夹将包含具有特定作业的不同 php 文件。
- 控制器:
A controller is the link between a user and the system. It provides
the user with input by arranging for relevant views to present
themselves in appropriate places on the screen. It provides means for
user output by presenting the user with menus or other means of giving
commands and data. The controller receives such user output,
translates it into the appropriate messages and pass these messages on
to one or more of the views.
将管制员想象成警察。检查客户端请求是否合法(尤其是涉及表单验证时)。当控制器验证请求时,它会调用模型(可选:取决于您是否需要 get/set 信息并使用数据库),然后是视图。
- 型号:
Models represent knowledge. A model could be a single object (rather
uninteresting), or it could be some structure of objects.
There should be a one-to-one correspondence between the model and its
parts on the one hand, and the represented world as perceived by the
owner of the model on the other hand.
- 查看:
A view is a (visual) representation of its model. It would ordinarily
highlight certain attributes of the model and suppress others. It is
thus acting as a presentation filter.
A view is attached to its model (or model part) and gets the data
necessary for the presentation from the model by asking questions. It
may also update the model by sending appropriate messages. All these
questions and messages have to be in the terminology of the model, the
view will therefore have to know the semantics of the attributes of
the model it represents.
视图的有趣之处在于您可以将 HTML 页面分解为多个部分。主要思想是创建一个 header.php
和一个不会有太大变化的 footer.php
(取决于您需要的 css/js )。然后您只需调用 views
即可填充 html 页面的主体。
这很有用,因此当客户端请求主页时,您可以简单地执行以下操作:
include header.php;
include home.php;
include footer.php;
让我知道这是否有用。
如果您仍然不确定我在说什么,请随时阅读以下内容:
Youtube videos tutorial on how to create an MVC structure (basic)
Youtube videos tutorial on how to create an MVC structure (advanced)
我(在空闲时间)创建了一个 html 页面,该页面使用 PHP 创建我的动态对象。 此页面调用我的 javascript 以接收来自 AJAX 用户的输入。 我的对象使用 AJAX 作为输入(PHP 执行 $_GET),然后我的对象将打开到我的 PDO mySQL 数据库的连接,执行查询并接收详细信息。它显示了我的对象和回声 HTML5 的细节,我使用 CSS 来做一些不错的功能。
它工作正常。我学到了很多(CSS 很棒),但是与其他编程语言相比,这在学习上非常相似,但又非常不同! 我发现它的不同之处在于...对于我想做的任何事情,总是有 许多 不同的方法来做。由于这是一组共同发挥作用的语言(PHP、javascript、CSS3 和 HTML5)。
目前我以某种方式避免了 jQuery,因为我正在学习并且更喜欢以困难的方式做所有事情。但是我注意到很多这样的插件,例如条形图,都是在 javascript 中创建的,并以数组的形式在那里提供数据。
现在我想要第二个页面,它的功能与第一个页面相同,但访问不同的数据并可能执行不同的操作,但它的显示效果非常相似。 所以我希望能够再次使用我的对象,只是给它不同的参数、不同的输入等等……就好像我刚刚使用了一个插件一样。所以现在我正在考虑在 js 中实例化它并从那里输入数据。 我只是想要一些好的指导,因为我刚开始,我学得越多,它就变得越广泛:)
这就是我的问题所在: 问:HTML5/js/PHP/CSS 中是否有标准的编程方式来创建可重用对象? 欢迎参考和 expertise/experience,我不想开始辩论。我想遵循一个标准。
我不是真的 100% 确定你在问什么 - 我从你的措辞中猜测你是一个编程新手。
为了回答你的问题(某种程度上),最接近 Javascript、PHP 和(不是真的)HTML 和 CSS 之间的公共接口的东西将是 JSON,或 Javascript 对象表示法。 PHP 有库可以读取 JSON,而 JavaScript 可以本地读取它(使用 jQuery 更好)。一些数据库(CouchDB,在某种程度上,MongoDB、Neo4j 等)甚至会几乎逐字地存储您的 JSON。
在任何情况下,存储数据的方式都应该在数据库中进行,并且 JSON,无论使用何种数据库,通常都被认为是在前端和后端之间进行通信的最佳方式代码(顺便说一下,它明确区分了 HTML/CSS/JS 和 PHP)。
不清楚你到底在问什么,但这是我对我的理解的回答。
服务器端组织:
如果您要创建一个大项目,我强烈建议您使用 PHP framework
(symphony, codeigniter 等),如果您不这样做,请考虑以下内容:
1.遵循 MVC 结构
MVC 结构可以用多种不同的方式表示。但是,为简单起见,您可以通过创建 3 个文件夹(controller、model、view)来完成此操作。
每个文件夹将包含具有特定作业的不同 php 文件。
- 控制器:
A controller is the link between a user and the system. It provides the user with input by arranging for relevant views to present themselves in appropriate places on the screen. It provides means for user output by presenting the user with menus or other means of giving commands and data. The controller receives such user output, translates it into the appropriate messages and pass these messages on to one or more of the views.
将管制员想象成警察。检查客户端请求是否合法(尤其是涉及表单验证时)。当控制器验证请求时,它会调用模型(可选:取决于您是否需要 get/set 信息并使用数据库),然后是视图。
- 型号:
Models represent knowledge. A model could be a single object (rather uninteresting), or it could be some structure of objects.
There should be a one-to-one correspondence between the model and its parts on the one hand, and the represented world as perceived by the owner of the model on the other hand.
- 查看:
A view is a (visual) representation of its model. It would ordinarily highlight certain attributes of the model and suppress others. It is thus acting as a presentation filter.
A view is attached to its model (or model part) and gets the data necessary for the presentation from the model by asking questions. It may also update the model by sending appropriate messages. All these questions and messages have to be in the terminology of the model, the view will therefore have to know the semantics of the attributes of the model it represents.
视图的有趣之处在于您可以将 HTML 页面分解为多个部分。主要思想是创建一个 header.php
和一个不会有太大变化的 footer.php
(取决于您需要的 css/js )。然后您只需调用 views
即可填充 html 页面的主体。
这很有用,因此当客户端请求主页时,您可以简单地执行以下操作:
include header.php;
include home.php;
include footer.php;
让我知道这是否有用。
如果您仍然不确定我在说什么,请随时阅读以下内容:
Youtube videos tutorial on how to create an MVC structure (basic)
Youtube videos tutorial on how to create an MVC structure (advanced)