需要一个smarty 写的注册登录页面的代码,另外需要项目建立需要的什么文件能截图,百度搜索的不能用,本人想通过这个学习下samrty,我这里先谢谢了。
回复讨论(解决方案)
在线等,可以加qq906988410
我不明白你什么意思?smarty的作用就是替换目的是更好地执行页面分离,在页面中不显示PHP代码,把PHP的变量在控制器里替换掉,像你说的那样注册页面根本用不到PHP变量,你直接写一个HTML文件当模板里面写点JAVASCRIPT验证不就完了吗?静态注册页面你可以百度下。。
smarty的作用你没弄明白,没有PHP变量根本不用替换。
我需要一个用smarty写的注册的代码 ,但是我不会用samarty,所以想要一个例子 ,参考学习一下,在网上看的介绍什么,我做了一下没有成功,感觉没有samarty的影子,所以希望大神们给一个
在线等不到了么
把你写的发上来让个大家帮你看看。
smarty就是程序模板分离没什么难的
建议看看php+smarty配置安装使用。
自己写一个smarty自定义函数,按照规范放到插件目录下就行了呗.......比如
smarty的可扩展性非常好,所以系统函数并不多,你需要什么功能,你就可以自己定义,规范也挺简单的,
比如smarty_function_自定义函数名,然后把文件名也写成这样,然后放到plugin目录下就行了。
smarty的作用不仅仅是界面分离的一种正则替换,缓存技术才是关键,不过这个也不过是filemtime和crc32等等的校验
所以smarty的关键还是学好php,,php是怎么实现的,smarty就是怎么做的
======================sql========================
CREATE TABLE `user` (
`user_id` int(5) NOT NULL AUTO_INCREMENT,
`user_name` varchar(20) NOT NULL,
`password` varchar(20) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8
========================db.php=====================<?phpclass DB { private $host; private $db_name; private $user_name; private $password; private $conn; public function __construct($host, $user_name, $password, $db_name) { $this->host = $host; $this->user_name = $user_name; $this->password = $password; $this->db_name = $db_name; $this->connect(); } public function connect() { $this->conn = mysql_connect($this->host, $this->user_name, $this->password) or die("数据库连接失败!"); mysql_select_db($this->db_name); mysql_query("SET CHARACTER SET utf8"); } public function getObj($sql) { $rs = mysql_query($sql, $this->conn) or die (mysql_error()); $arr = array(); while ($row = mysql_fetch_array($rs)) { if (!empty($row)) $arr[] = $row; } return $arr; } public function add_data($table, $fields = array(), $values = array()) { $sql = "insert into " . $table . "(" ; for($i = 0; $i < count($fields); $i++) { if ($i < count($fields) - 1) $sql .= $fields[$i] . ','; else $sql .= $fields[$i] . ")"; } $sql .= " values ("; for($i = 0; $i < count($values); $i++) { if ($i < count($values) - 1) $sql .= "'" . $values[$i] . "'" . ','; else $sql .= "'" . $values[$i] . "')"; } mysql_query($sql, $this->conn) or die (mysql_error()); $insert_id = mysql_insert_id($this->conn) or die (mysql_error()); return $insert_id; } public function close() { mysql_close($this->conn); } }$db = new DB('localhost', 'root', '', 'test');?>==========================User类=====================================<?phprequire './Mysql/db.php';?><?phpclass User { private $user_name; private $password; private $table; function __construct($table, $user_name, $password) { $this->user_name = $user_name; $this->password = $password; $this->table = $table; } public function add_user() { global $db; $user_data = array($this->user_name, $this->password); return $db->add_data($this->table, array('user_name', 'password'), $user_data); } public function get_user($user_name) { global $db; $sql = "select * from $this->table where user_name = '" . $user_name . " '"; return $db->getObj($sql); } }?>===================user.php================================<?phpsession_start();header("Content-type: text/html; charset=utf-8"); require 'User.class.php';require './Smarty-2.6.26/libs/Smarty.class.php';$smarty = new Smarty;$smarty->compile_check = true;$smarty->debugging = false;if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'register') { $user_name = $_REQUEST['user']; $password = $_REQUEST['password']; $user = new User('user', $user_name, $password); $user_arr = $user->get_user($user_name); if (empty($user_arr)) { $user->add_user(); echo "用户注册成功!" . "<br/>"; } else { echo "用户已经存在!" . "<br/>"; }} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'login') { $user_name = $_REQUEST['user']; $password = $_REQUEST['password']; $user = new User('user', $user_name, $password); $user_arr = $user->get_user($user_name); if (empty($user_arr)) { echo "用户不存在!" . "<br/>"; } else { if ($user_arr[0]['user_name'] == $user_name && $user_arr[0]['password'] == $password) { echo "登录成功!"; /*** * 然后就是记录session,跳转到登录成功的页面 * 把用户名使用smarty常用的assign变量方法,在注册成功的页面取出来, */ } }} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'login_page'){ $smarty->display('login.html');} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'register_page'){ $smarty->display('register.html');} else { $smarty->display('register.html');}?>==============register.html==============<!DOCTYPE html><html> <head> <title>用户注册</title> <meta charset="UTF-8"> </head> <body> <form action="/csdn/user.php" method="post" /> User Name: <input type="text" name="user" /><br/><br/> Password: <input type="password" name="password" /><br/><br/> <input type="submit" name="register" value="register"/> | <a href="/csdn/user.php?act=login_page">登录</a> <input type="hidden" name="act" value="register" /> </form> </body></html>==============login.html=========================<!DOCTYPE html><html> <head> <title>用户登录</title> <meta charset="UTF-8"> </head> <body> <form action="/csdn/user.php" method="post" /> User Name: <input type="text" name="user" /><br/><br/> Password: <input type="password" name="password" /><br/><br/> <input type="submit" name="login" value="login"/> | <a href="/csdn/user.php?act=register_page">注册</a> <input type="hidden" name="act" value="login" /> </form> </body></html>
elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'login_page'){ $smarty->assign("title", "用户登录"); $smarty->display('login.html');} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'register_page'){ $smarty->assign("title", "用户注册"); $smarty->display('register.html');} else { $smarty->assign("title", "用户注册"); $smarty->display('register.html');}<html> <head> <title>{$title}</title> <!--assign进来的变量--> <strong></strong> <meta charset="UTF-8"> </head> <body> <form action="/csdn/user.php" method="post" /> User Name: <input type="text" name="user" /><br/><br/> Password: <input type="password" name="password" /><br/><br/> <input type="submit" name="login" value="login"/> | <a href="/csdn/user.php?act=register_page">注册</a> <input type="hidden" name="act" value="login" /> </form> </body></html>
你那个user类是那个文件里加的,还有你最后这段代码是加在那的,这个可以运行么
谁能告诉我么 也给分的
你那个user类是那个文件里加的,还有你最后这段代码是加在那的,这个可以运行么
最后这段就是举个assign函数的例子而已
smarty 没有什么难的么,头疼 东西多啊
smarty 没有什么难的么,头疼 东西多啊
模板的原理大多数都是一样 就是查找替换, 然后就需要PHP的数组和字符串处理知识,学会了这两个就能做功能了,PHP上手就是这么简单
你这个不能用 的 但是分还是给你
亲,可以用,这是我写完经过调试验证的

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor