Joomla component manufacturing process Admin. hello_world.php

Source: Internet
Author: User
Admin. hello_world.php

// This will verify whether joomla calls this file to prevent unauthorized and direct running of this file, which is very important for security.
Defined ('_ valid_mos') or die ('direct access to this location is not allowed .');

// Query the database and set HTML output //
/*
Development Time: 2007-12-17
Developer: yoshow
Gmail: ruanyu83@gmail.com
URL: http://hi.baidu.com/joomla123
Database Query and set HTML output
*/

// Call the following two files: class. hello_world.php and admin.hello_world.html. php.
Require_once ($ mosconfig_absolute_path. "/Administrator/components/com_hello_world/class. hello_world.php ");
Require_once ($ mainframe-> getpath ('admin _ HTML '));

// Create an selection and switch statement. If there is a variable $ act, we will redefine a new variable $ task. in this way, $ Act is used to display text, and $ task is used to save, delete, and so on ..
Switch ($ Act ){
Default:
$ Task = "showtext ";
Break;
}

// This switch statement runs the required functions based on $ task.
Switch ($ task ){
Case "save ":
Save ($ option );
Break;
Case "delete ":
Delete ($ option, $ id );
Break;
Case "new ":
$ Id = '';
Edit ($ option, $ id );
Break;
Case "edit ":
Save ($ option, $ id [0]);
Break;
Case "showtext ":
Showtext ($ option );
Break;
}

// Our first function that saves the content we created or are editing
Function save ($ option ){
// Declare $ database as a global variable
Global $ database;
// This defines the new $ row variable to store the information inserted into the database. $ row is an instance of the moshello_world class defined in the class. hello_world.php file.
$ ROW = new moshello_world ($ database );
// If $ row returns a null value, the error message is displayed and the previous window is returned.
If (! $ Row-> BIND ($ _ post )){
Echo "N ";
Exit ();
}
// If the write operation on the database cannot be completed, the error message is displayed and the previous window is returned. This will only occur when an exception occurs in the database.
If (! $ Row-> store ()){
Echo "N ";
Exit ();
}
// If everything is normal, redirect your browser to the main option window and display "saved ".
Mosredirect ("index2.php? Option = $ option "," saved ");
}

// ManyCodeRefer to the previous explanation and I will not go into details here.
Function edit ($ option, $ UID ){
Global $ database;
$ ROW = new moshello_world ($ database );
// After $ row is defined and declared as the moshello_world class, $ UID-related data is loaded. $ uid is the value of $ ID for the content we want to edit.
$ Row-> load ($ UID );
// Send $ row to admin.hello_world.html. php.
Html_hello_world: Edit ($ option, $ row );
}

Function Delete ($ option, $ CID ){
Global $ database;
// This checks whether there are deleted objects. If it is null, a prompt is displayed and the last window is returned.
If (! Is_array ($ CID) | count ($ CID) echo "N ";
Exit;
}

// This checks whether $ CID (the number of columns storing the $ id value of all objects to be deleted) is null, if it is not empty, it creates a list Of all IDs separated by commas and stores them in the string $ CIDS. Then, it deletes the IDS, if an operation error occurs, the previous window is returned.
If (count ($ CID )){
$ CIDS = implode (',', $ CID );
$ Database-> setquery ("delete from jos_hello_world where ID in ($ CIDS )");
If (! $ Database-> query ()){
Echo "N ";
}
}
Mosredirect ("index2.php? Option = $ option ");
}

// This is our main output function. We will create a list of text to be output. For more information, see the previous section.
Function showtext ($ option ){
Global $ database;
# Do the main database query
$ Database-> setquery ("select * From jos_hello_world order by ID ");
$ Rows = $ database-> loadobjectlist ();
If ($ database-> geterrornum ()){
Echo $ database-> stderr ();
Return false;
}
Html_hello_world: showtext ($ option, $ rows );
}

?>

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.