Example (Smarty + FCKeditor News system) _ PHP Tutorial

Source: Internet
Author: User
Instance (Smarty + FCKeditor News system ). The following is the content of the main file index. php: Copy the code as follows: metahttp-equivContent-Typecontenttexthtml; charsetutf-8? Phprequire (. global. php); require (. smartylibs is the content of index. php in the main file below:

The code is as follows:


Require ('./global. php ');
Require ('./smarty/libs/Smarty. class. php ');
Require ('./mysql. php ');
Require ('./FCKeditor/fckeditor. php ');
$ Action = $ _ REQUEST ['action'];
// Define a function to call FCK
Function editor ($ input_name, $ input_value)
{
Global $ smarty;
$ Editor = new FCKeditor ($ input_name );
$ Editor-> BasePath = "./FCKeditor/"; // specify the editor path

$ Editor-> ToolbarSet = "Default"; // The editor toolbar contains Basic (Basic tools) and Default (all tools). Select
$ Editor-& gt; Width = "100% ";
$ Editor-& gt; Height = "320 ";
$ Editor-> Value = $ input_value;
$ Editor-> Config ['autodetectlanguage'] = true;
$ Editor-> Config ['defaultlanguage'] = 'en'; // language
$ FCKeditor = $ editor-> CreateHtml ();

$ Smarty-> assign ("editor", $ FCKeditor); // specify a region
}

Switch ($ action ){

Case 'addnewview ':

$ Smarty = new Smarty ();
$ Smarty-> template_dir = './template ';
$ Smarty-> compile_dir = './smarty/templates_c ';
$ Smarty-> assign ('page _ title', 'create new ');
$ Smarty-> assign ('actionvalue', 'addnew ');
Editor ('content', ''); // call the editor and define the text domain name as content (corresponding to $ _ REQUEST ['content'] in addnews below)
$ Smarty-> display('addnews.htm ');
Break;

Case 'addnew ':
$ Title = $ _ REQUEST ['title'];
$ Content = $ _ REQUEST ['content'];
$ Db = new mysql ();
$ Button = $ _ REQUEST ['submit '];

If (empty ($ title) | empty ($ content )){
Echo "complete! ";
} Else {
$ SQL = "insert into news values (id, 'admin', '$ title',' $ content', NOW ())";
$ Db-> query_exec ($ SQL );
Echo "operation successful! ";
}
Break;

Case 'editnewview ':
$ Smarty = new Smarty ();
$ Smarty-> template_dir = './template ';
$ Smarty-> compile_dir = './smarty/templates_c ';
$ Smarty-> assign ('page _ title', 'modify News ');
$ Smarty-> assign ('actionvalue', 'addnew ');
$ Id = $ _ REQUEST ['id'];

$ Query = "select * from news where id = $ id ";
$ Db = new mysql ();
$ Result = $ db-> query_exec ($ query );
$ Rs = $ result-> fetch_assoc ();

$ Smarty-> assign ('title', $ rs ['title']);
// $ Smarty-> assign ('content', $ rs ['content']);
$ Smarty-> assign ('actionvalue', 'editnews ');
$ Smarty-> assign ('id', $ rs ['id']);
Editor ('content', $ rs ['content']);
$ Smarty-> display('addnews.htm ');
Break;

Case 'editnews ':
$ Title = $ _ REQUEST ['title'];
$ Content = $ _ REQUEST ['content'];
$ Id = $ _ REQUEST ['id'];

$ Button = $ _ REQUEST ['submit '];
$ Db = new mysql ();
If ($ button = 'submit '){
$ SQL = "update news set title = '$ title', content =' $ content', date = NOW () where id = $ id ";
$ Db-> query_exec ($ SQL );
Echo "operation successful! ";
}
Break;

Case 'delnews ':
$ Db = new mysql ();
If ($ checkbox! = "" Or count ($ checkbox )! = 0 ){
For ($ I = 0; $ I $ Db-> query_exec ("delete from news where id = '$ checkbox [$ I]'");
}
}
Echo "operation successful! ";
Break;

Default:
$ Smarty = new Smarty ();
$ Smarty-> template_dir = './template ';
$ Smarty-> compile_dir = './smarty/templates_c ';
$ Smarty-> assign ('page _ title', 'News management ');
$ Smarty-> assign ('actionvalue', 'delnews ');

$ Query = "select * from news ";
$ Db = new mysql ();
$ Result = $ db-> query_exec ($ query );

While ($ rs = $ result-> fetch_assoc ()){
$ Array [] = array ("id" => $ rs ['id'], "title" => $ rs ['title'], "date" => $ rs ['Date']);
$ Smarty-> assign ('news', $ array );
}

$ Smarty-> display('index.htm ');

}
?>

Below is the content of the template file index.htm
Http://www.w3.org/TR/html4/loose.dtd>



{$ Page_title}




News management











System Management

Add News






Addnews.htm
Http://www.w3.org/TR/html4/loose.dtd>




{$ Page_title}



News management login











System Management



Add News





Note: The database is already in the attachment. First, create a new database named new, and then import the table.
System User Name: admin Password: admin
Package download
Download this file

The authorization code is as follows: metahttp-equiv = "Content-Type" content = "text/html; charset = utf-8 "? Php require ('./global. php'); require ('./smarty/libs /...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.