English 中文(简体)
框架和模板发动机之间的差别如何?
原标题:What are the differences between framework and template engine?

挖掘机等框架与像mar类模范发动机之间有何区别?

我首先要谈什么?

问题回答

Template/61/6s,使网络设计人的生活更加方便。 Framework供方案人员使用。

框架可包含一个或多个模板发动机。 由于框架是方案设计人,新的或方案设计人自己的模板发动机可能被纳入框架。

作为一个方案家,必须同设计商合作,在PHP中,你实际上不需要一个模板发动机,因为PHP本身可能被(X)超文本处理。

Creating a template engine, as a programmer

事实证明,PHP本身可以被用作一种排外发动机,这里就是你如何从逻辑上推平不同的商业逻辑。

它是一家得到家庭支持的 du球缝发动机。 它不完整,并不安全。 它只是向你们展示节奏的基本想法的原型。

也许你们已经听到了MVC, 或者说,它没有。 下面描述的做法与此类似,但你没有计划OOP或使用framework

Your "views" are simply templates which get some variables from your script. In the main script (here greet.php), you only do the "business logic". "Business logic" includes all database operations, working with sessions, doing all the maths and checking for valid input, eventually filtering it.

然后,你们必须做的是储存你想要在中间变量中显示的数据。 在下文中,该标题、名称、 $和er。

这一功能使(a)项具有重要意义:它利用变量——,将我们的文字的商业逻辑从外部世界纳入该模板,而整个模板仅存在于该功能之内。

请注意,所选变量在第二个参数的相关指数之后标明,以便(......)。 如果你的模板没有要求变数有不同的名称,那么,你可以把一些线缩小,例如:

$export = compact( title , name , showdata , errors );

变数的美元/美元将不再存在于你的模板中。 相反,相同的变数将与你的商业逻辑说明,即how数据相同。

greet.php

<?php
$title =  Contact ;
$name =  Guest ;
$showdata = FALSE;
$errors = array();
if(isset($_POST[ submit ])) {
        if(isset($_POST[ name ]) && $name = trim($_POST[ name ])) {
                $name = strip_tags($name);
                $showdata = TRUE;
        }
        else {
                $errors[] =  Missing name. ;
        }
}
$export = array(
         title  => $title,
         name  => $name,
         do_greet  => $showdata,
         errors  => $errors
);

render( greet_view.php ,$export);

function render($template,$data) {
        extract($data);
        return include $template;
}

One important note on templates like this: if you try to access global data, database connections, superglobal arrays like $_SESSION, $_GET, $_POST, $_COOKIE, $_FILES, $_SERVER, etc, in your templates, then you re not using this technique properly. Your aim is to separate completely the logic from the view.

如果你确实需要这种数据,那么通过中间变量提供这种数据,例如:

$export = array(
         title  => $title,
         name  => $name,
         do_greet  => $showdata,
         errors  => $errors,
         referer  => htmlentities($_SERVER[ HTTP_REFERER ])
);

这里是《观点守则》或模板greet_view.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">                                                                                  
<head>
        <title><?php echo $title ?></title>
</head>
<body>
<?php
if($do_greet) {
        echo  Hi  ,$name;
}
if(count($errors)) {
        if(count($errors)>1) {
                echo  <p class="error"> ,implode( </p><p class="error"> ,$errors), </p> ;
 }
 else {
                echo  <p class="error"> .$errors[0]. </p> ;
 }
}
?>
<form method="post">
        <input name="name" />
        <input type="submit" name="submit" />
</form>
</body>
</html>

<>Disapper:提出的代码不干净,也不安全或完美。 我的用意只是把你放在正确的轨道上。 从事更多研究的是your工作


The framework

这是模板发动机部分。 框架提供功能(以职能和(或)类别的形式)来解决共同问题,如认证、授权、向适当的档案/分类(监控人员在监控中心世界)提出申请等等。

这一功能不同于CMS,它不准备作为用户使用。 框架的不同组成部分必须由方案管理人共同进行。 由于方案管理员只需要做这一连接,而不必(再)为每个项目和每个项目提供功能,因此,一个框架使得方案拟定更加可行,使方案管理员能够集中精力处理具体项目的实际问题。

象上文所述的模板发动机一样,也可成为这一框架的一部分,而使()功能可以是控制器的一种方法(MVC术语)。

框架比模板发动机更为复杂。 框架可以包含一个模板发动机,但不能逆转。 一种框架可以无几地帮助你建立你(网)的申请。 模板发动机只是用来将变数归入您预定格式的html模板。

简言之:

<<>template的发动机只不过是一个更先进的探测器。 它搜索模板中的特别标签,并以相应的数值取而代之。 较先进的发动机(如智能型)也有 lo和条件。

web framework(如Zend)”是网页的大多数核心内容,同时进行页面查询,并将其转交负责处理请求的操作人员,而且通常还将回复信息转交一个逻辑和布局的模板发动机。 网络框架(是其他框架类型,即全球倡议框架、网络框架、制图框架等)通常都有用户帮助,帮助你满足网站所有典型的需要、形式核查、会议管理、Captcha生成、URL重写。

象Zentd Framework这样的框架基本上延伸到PHP上,而Smarty则是一个模版发动机,简单地把所有你的PHP变量与前端(html)分开,同时支持简单处理内容的方法。

我建议你开始学习聪明才智,因为你会感到惊讶的是,把你的前端设计与你的购买力平价编码结合起来会更加容易。

http://eaccelerator.net/“rel=”http://eaccelerator.net/“nofollow noreferer” http://eaccelerator.net/。 加快步伐。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签