- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我(在空闲时间)创建了一个 html 页面,该页面使用 PHP 来创建我的动态对象。此页面调用我的 javascript 以使用 AJAX 接收用户的输入。我的对象使用 AJAX 进行输入(PHP 执行 $_GET),然后我的对象将打开到我的 PDO mySQL 数据库的连接,执行查询并接收详细信息。通过详细信息,它显示了我的对象并回显了 HTML5,我使用 CSS 实现了一些不错的功能。
它工作正常。我学到了很多东西(CSS 很棒),但与其他编程语言相比,这在学习上非常相似,但又非常不同!我发现它的不同之处在于……对于我想做的任何事情,总是有许多不同的方法来做。由于这是一组一起运行的语言(PHP、javascript、CSS3 和 HTML5)。
我暂时以某种方式避免使用 jQuery,因为我正在学习并且更喜欢以困难的方式做所有事情。然而,我注意到很多这样的插件,例如条形图,都是用 javascript 创建的,并以数组的形式提供数据。
现在我想要第二个页面,它的功能与第一个页面相同,但访问不同的数据并可能执行不同的操作,但它的显示效果非常相似。所以我希望能够再次使用我的对象,只是给它不同的参数、不同的输入等等……就好像我刚刚使用了一个插件一样。所以现在我正在考虑在 js 中实例化它并从那里输入数据。我只是想要一些很好的指导,因为我刚开始,我学得越多,它就变得越广阔:)
所以这就是我的问题所在:问:在 HTML5/js/PHP/CSS 中是否有一种标准的编程方式来创建可重用的对象?欢迎提供引用资料和专业知识/经验,我不想展开辩论。我想要一个标准来遵循。
最佳答案
不清楚您到底在问什么,但这是我对我的理解的回答。
如果您要创建一个大元素,我强烈建议您使用 PHP 框架
(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.
将控制者想象成警察。检查客户端请求是否合法(尤其是在表单验证方面)。当 Controller 验证请求时,它会调用模型(可选:取决于您是否需要获取/设置信息并使用数据库),然后是 View 。
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.
View 的有趣之处在于您可以将 HTML 页面分解为多个部分。主要思想是创建一个 header.php
和一个 footer.php
,它们不会有太大变化(取决于您需要的 css/js)。然后您只需调用将填充 html 页面主体的 views
。
这很有用,因此当客户端请求主页时,您可以简单地执行以下操作:
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)
关于javascript - 在 HTML5/js/PHP/CSS 中是否有一种标准的编程方式来创建可重用的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29055824/
我最近在读 CSAPP。在 10.9 节中,它说标准 I/O 不应该与 socket 一起使用,原因如下: (1) The restrictions of standard I/O Restricti
似乎是一个足够标准的问题,可以保证解决方案中的标准设计: 假设我想在文件中写入 x+2(或更少)个字符串。 x 字符串构成一个部分的内容,这两个字符串构成该部分的页眉和页脚。要注意的是,如果内容中没有
代码版本管理 在项目中,代码的版本管理非常重要。每个需求版本的代码开发在版本控制里都应该经过以下几个步骤。 在master分支中拉取该需求版本的两个分支,一个feature分支,
我有以下sql查询,我需要获取相应的hibernate条件查询 SELECT COUNT(DISTINCT employee_id) FROM erp_hr_payment WHERE payment
所以我正在编写一些代码,并且最近遇到了实现一些 mixin 的需要。我的问题是,设计混音的正确方法是什么?我将使用下面的示例代码来说明我的确切查询。 class Projectile(Movable,
我的环境变量包含如下双引号: $echo $CONNECT_SASL_JAAS_CONFIG org.apache.kafka.common.security.plain.PlainLoginModu
示例: /** * This function will determine whether or not one string starts with another string. * @pa
有没有办法在 Grails 中做一个不区分大小写的 in 子句? 我有这个: "in"("name", filters.tags) 我希望它忽略大小写。我想我可以做一个 sqlRestriction
我搜索了很长时间,以查找将哪些boost库添加到std库中,但是我只找到了一个新库的完整列表(如此处:http://open-std.org/jtc1/sc22/wg21/docs/library_t
我已经通过使用这个肮脏的黑客解决了我的问题: ' Filter managerial functions ActiveSheet.Range("$A$1:$BW$2211").Auto
因此,我很难理解我需要遵循的标准,以便我的 Java 程序能够嵌入 HTML。我是否只需将我的主类扩展到 Applet 类,或者我还需要做更多的事情吗?另外,在我见过的每个 Applet 示例中,它都
我对在 Hibernate 中使用限制有疑问。 我必须创建条件,设置一些限制,然后选择日期字段最大值的记录: Criteria query = session.createCriteria(Stora
我有标准: ICriteria criteria = Session.CreateCriteria() .SetFetchMode("Entity1", FetchMo
我很难编写条件来选择所有子集合或孙集合为空的实体。我可以将这些作为单独的条件来执行,但我无法将其组合成一个条件。 类结构: public class Component { p
@Entity class A { @ManyToMany private List list; ... } @Entity class B { ... } 我想使用条件(不是 sql 查询)从 A
我的数据库中有以下表结构: Table A: Table B: Table C: _______________
请帮助我: 我有下一张 table : 单位 ID 姓名 用户 ID 姓名 利率 单位 ID 用户 ID 我不明白如何从 SQL 创建正确的条件结构: 代码: SELECT * FROM Unit W
我正在构建一个包含项目的网站,每个项目都有一个页面,例如: website.com/book/123 website.com/film/456 website.com/game/789 每个项目都可以
我需要使用两个属性的组合来过滤结果列表。一个简单的 SQL 语句如下所示: SELECT TOP 10 * FROM Person WHERE FirstName + ' ' + LastName L
我有一个“ super 实体”SuperEntity 和三个扩展父类(super class)的实体 ChildEntity1、...、ChildEntity3。 搜索数据库中的所有实体很容易,即我们
我是一名优秀的程序员,十分优秀!