美文网首页
开发企业网站 --后端页面

开发企业网站 --后端页面

作者: 潘肚饿兵哥哥 | 来源:发表于2019-09-25 22:25 被阅读0次

\color{rgba(254, 67, 101, .8)}{将之前的项目分离:}
\color{rgba(254, 67, 101, .8)}{1.把smarty文件复制到company项目中}
\color{rgba(254, 67, 101, .8)}{新建一个templates文件夹}

image.png

\color{rgba(254, 67, 101, .8)}{把smarty公用部分复制到项目公共页面index.php[后台首页]中}

//这一部分是公共的,直接复制到公共文件index.php里
    require_once('smarty/Smarty.class.php');
    $smarty = new smarty; //创建一个对象
    
    //因为在smarty.class.php(341行)中,设置了用{}接收解析php传过去的函数
    //如果要写css样式就解析不了,因为css样式也是用{}的
    //因此,要修改他接收解析php函数的符号
    //多加一个尖括号就可以了
    $smarty -> left_delimiter = '<{';
    $smarty -> right_delimiter = '}>';

\color{rgba(254, 67, 101, .8)}{然后在admin文件夹中的index.php[后台首页]文件中调用index.html}


<?php
    require_once('init.php');
     //调用模板 goods_list.html
     $smarty -> display('idnex.html');//此时,会自动生成一个文件夹templates_c
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>后台首页</h1>
</body>
</html>

\color{rgba(254, 67, 101, .8)}{并将此文件中(admin中的index.php[后台首页])的html代码放到templates中}
\color{rgba(254, 67, 101, .8)}{在templates中新建文件index.html文件}
\color{rgba(254, 67, 101, .8)}{将admin中的index.php[后台首页]文件的html代码放到此文件中}

\color{rgba(53, 93, 129, .8)}{相当于此时要访问后端:}

\color{rgba(53, 93, 129, .8)}{1.公共首页index.php创建一个常量传递到init.php(初始化文件)中}

\color{rgba(53, 93, 129, .8)}{2.后端首页index.php调用此公共文件init.php文件}
\color{rgba(53, 93, 129, .8)}{并将其使用smarty传到templates文件夹的index.html中}

\color{rgba(53, 93, 129, .8)}{3.在浏览器中输入 www.yixing666.com?m=admin\&c=index}

\color{rgba(53, 93, 129, .8)}{显示结果}

image.png

<?php
    require_once('init.php');
    $smarty -> display('index.html');
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>后台首页</h1>
</body>
</html>

\color{rgba(254, 67, 101, .8)}{前面的做法是把后端的index.html页面放到模板文件夹templates中}
\color{rgba(254, 67, 101, .8)}{但是这样有一个问题是如果前端的首页模板也放进来了就重名了}
\color{rgba(254, 67, 101, .8)}{所以最好的办法就是在templates文件夹中再建子文件夹}
\color{rgba(254, 67, 101, .8)}{这就需要进行修改}

修改:

  1. $smarty -> template_dir = array('./templates/'.$m.'/');加入这个对象
  2. 在templates文件夹中新建子文件夹admin,并将之前在这个文件夹下建的index.html文件剪切到admin文件夹中
image.png

\color{rgba(254, 67, 101, .8)}{同时,还是在templates文件夹下再建一个文件夹home}
\color{rgba(254, 67, 101, .8)}{在home文件夹中建文件index.html}

image.png

\color{rgba(254, 67, 101, .8)}{前端部分结构改造}

\color{rgba(254, 67, 101, .8)}{再将之前templates下面的home文件夹中的index.php文件中的html代码剪切过来}
\color{rgba(254, 67, 101, .8)}{粘贴到这个templates-->home-->index.html中}


<?php
    require_once('init.php');
    $smarty -> display('index.html');
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>前台首页</h1>
</body>
</html>
image.png
输入www.yixing666.com能看到这个页面就证明迁移成功了

\color{rgba(254, 67, 101, .8)}{现在,之前的结构就改变成新的了}
\color{rgba(254, 67, 101, .8)}{之前是项目文件下有两个文件夹和两个文件,分别是:}
\color{rgba(254, 67, 101, .8)}{1.前端home文件夹 }
\color{rgba(254, 67, 101, .8)}{2.后端admin文件夹}
\color{rgba(254, 67, 101, .8)}{3.公共首页(入口文件)index.php}
\color{rgba(254, 67, 101, .8)}{4.404文件}
\color{rgba(254, 67, 101, .8)}{现在是加入了smarty文件夹和新建了templates模板文件夹}
\color{rgba(254, 67, 101, .8)}{并在template下建home和admin文件夹}
\color{rgba(254, 67, 101, .8)}{分别用于装前后端的html文件}
\color{rgba(254, 67, 101, .8)}{把之前装在admin和home里的index.php中的html代码迁移到templates相应文件中}

\color{rgba(53, 93, 129, .8)}{这就叫MVC模式}
\color{rgba(254, 67, 101, .8)}{其实就是把他分开处理}

\color{rgba(254, 67, 101, .8)}{各个模块不要都在一个文件里}


\color{rgba(254, 67, 101, .8)}{下面先处理后台文件:}
\color{rgba(254, 67, 101, .8)}{后台也需要一个后台的管理界面}
\color{rgba(254, 67, 101, .8)}{在项目文件夹下建一个文件admin.php}
\color{rgba(254, 67, 101, .8)}{因为之前代码写的需要用www.yixing666.com?m=admin\&c=index登陆}
\color{rgba(254, 67, 101, .8)}{这样登陆后台太麻烦,所以建一个admin.php文件做跳转}

<?php
    header("location:/?m=admin&c=index");
?>
image.png

\color{rgba(254, 67, 101, .8)}{此时搜索后台就可以简单一些:}
\color{rgba(254, 67, 101, .8)}{www.yixing666.com/admin.php}
\color{rgba(254, 67, 101, .8)}{之前要这样:}
\color{rgba(254, 67, 101, .8)}{www.yixing666.com?m=admin\&c=index}

image.png

\color{rgba(254, 67, 101, .8)}{在company下建一个新文件夹public公共文件}
\color{rgba(254, 67, 101, .8)}{public文件夹以后就用于存放css、js等公共文件}
\color{rgba(254, 67, 101, .8)}{再在这个公共文件夹中建子文件夹用于装前后台文件}
\color{rgba(254, 67, 101, .8)}{先建一个admin文件}
\color{rgba(254, 67, 101, .8)}{把后台模板H-ui\_admin的lib和static文件复制到admin中}

\color{rgba(254, 67, 101, .8)}{结构如下:}

image.png

\color{rgba(254, 67, 101, .8)}{然后将H-ui.admin模板中的login.html源码替换掉后端首页代码}

image.png

\color{rgba(254, 67, 101, .8)}{如果将login.html13行的地址改成href="/public/admin/static/h-ui/css/H-ui.min.css"}
\color{rgba(254, 67, 101, .8)}{就会变成这样:证明有效}

image.png

\color{rgba(254, 67, 101, .8)}{这个超链接就是这个模板在项目中的位置,但是如果这样写,就写死了}
\color{rgba(254, 67, 101, .8)}{所以需要用传参的形式,不能直接写死位置}

\color{rgba(254, 67, 101, .8)}{所以要通过配置文件init.php分配样式的路径到html页面}

\color{rgba(254, 67, 101, .8)}{init.php文件写常量}
\color{rgba(254, 67, 101, .8)}{smarty的变量需要分配}
\color{rgba(254, 67, 101, .8)}{但是常量不需要,使用常量的页面直接接收就可以}

//检测是否通过入口访问
    defined('TICKET') or die('Denny');

    //分配样式的路径到后端首页index.html
    //用常量分配路径,取名为__STATIC__
     //常量  不需要在这里分配,在需要接收这个常量的链接位置这样接收<{$smarty.const.__STATIC__}>
    
    define('__STATIC__', '/public/admin/');

/* 
1.define用来定义一个常量,常量也是全局范围的。不用管作用域就可以在脚本的任何地方访问
常量。一个常量一旦被定义,就不能再改变或者取消定义

2.defined用来检测常量有没有被定义,若常量存在,则返回 true,否则返回 false
*/

\color{rgba(254, 67, 101, .8)}{在要用到这个常量的页面,css和js 链接处接收这个常量}

<link href="<{$smarty.const.__STATIC__}>static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="<{$smarty.const.__STATIC__}>static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<link href="<{$smarty.const.__STATIC__}>static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="<{$smarty.const.__STATIC__}>lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="<{$smarty.const.__STATIC__}>lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="<{$smarty.const.__STATIC__}>static/h-ui/js/H-ui.min.js"></script>
</body>
</html>

\color{rgba(254, 67, 101, .8)}{效果已经出来了:}

image.png

\color{rgba(254, 67, 101, .8)}{左上角的后台管理系统字样式源文件中有一个logo.psd文件}

\color{rgba(254, 67, 101, .8)}{可以通过修改这个图片中的文字更换logo}

相关文章

  • 开发企业网站 --后端页面

    修改:$smarty -> template_dir = array('./templates/'.$m.'/')...

  • 前端小白必读:前端开发的演变

    本文介绍前端开发的历史和趋势,帮助前端小白快速了解前端开发。 静态页面阶段 互联网发展的早期,网站的前后端开发是一...

  • 【网站定制】企业网站开发|企业网站定制|企业网站运维

    【网站定制】企业网站开发|企业网站定制|企业网站运维 【网站定制】企业网站开发|企业网站定制|企业网站运维

  • 1.单页面应用程序

    网站交互方式 经典的多页面前后端耦合,开发和维护效率低下用户体验一般,点击刷新跳转,等待时间过长每个页面都需要重新...

  • 前端的发展历程

    一、静态页面阶段 互联网发展的早期,网站的前后端开发是一体的,即前端代码是后端代码的一部分。1.后端收到浏览器的请...

  • 【前端 Vue】07 - Vue-router

    1. 后端路由阶段 早期的网站开发整个HTML页面是由服务器来渲染的。服务器直接生产渲染好对应的HTML页面, 返...

  • 网页的发展历程(Vue)

    1、后端路由阶段 早期的网站开发整个HTML页面是由服务器来渲染的。服务器直接生产渲染好对应的HTML页面,返回给...

  • 前后端分离的好处

    1、前后端不分离 在前后端不分离的开发模式中,前端看到的页面效果都是由后端控制,由后端渲染页面或重定向,即后端要控...

  • Springboot中跨域问题解决

    需求: 在项目开发中,前后端分离,接口联调时候,前端页面直接调取后台接口,前后端开发使用不同的电脑,因此页面的aj...

  • 有了Swagger2,再也不用为写Api文档头疼了

    1、为什么要写Api文档 现在,前后端分离的开发模式已经非常流行,后端开发工程师只负责完成后端接口,前端页面的开发...

网友评论

      本文标题:开发企业网站 --后端页面

      本文链接:https://www.haomeiwen.com/subject/yneayctx.html