Joomla build analysis rsform as an Example

Source: Internet
Author: User

I. Portal for Building

First, analyze the following rsform entry file:

<? PHP/*** @ version 1.4.0 * @ package rsform! Pro 1.4.0 * @ copyright (c) 2007-2011 www.rsjoomla.com * @ license GPL, encrypt ('_ jexec') or die ('restricted access'); $ cache = & jfactory :: getcache ('com _ rsform '); $ cache-> clean (); // require the base controller master controller require_once (jpath_component.ds. 'controller. PHP '); // contains the Controller under the build directory. PHP file require_once (jpath_administrator.ds. 'components '. DS. 'com _ rsform '. DS. 'helpers '. DS. 'rsform. PHP '); help class // see if this is a request for a specific controller to see if there is a special controller $ controller = strtolower (jrequest: getword ('controller ')); // These are not controllers but legacy functions there are no controller groups, but there are traditional functions (this is not clear at the moment) if ($ controller = 'functions' | $ controller = 'adapter ') $ controller = '';
// A judgment is added here. If $ controller is not empty and com_form/controllers/controller. if the PHP file exists, execute the above Code. Otherwise, execute the following code. I have read that the file does not seem to exist in the directory.
if (!empty($controller) && file_exists(JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php'))
{Require_once (jpath_component.ds. 'controllers '. DS. $ controller. '. PHP '); $ controller = 'rsformcontroller '. $ controller; $ rsformcontroller = new $ controller ();} else $ rsformcontroller = new rsformcontroller (); // that is, the last execution is here, rsformcontroller () this class is Controller under com_rsform. PHP file.
$ Rsformcontroller-> execute (jrequest: getword ('task'); // The Controller executes the task // redirect if set $ rsformcontroller-> redirect ();?>

Next we will analyze them in sequence:

The upper-case Ds is the directory separator '/' or '\'. It is automatically set by the Framework, so developers do not need to worry about developing different versions for different operating systems. When using a local file, you should always use the 'ds' constant.

2. Create a controller

The controller is a little long. Let's take a look.

Class rsformcontroller extends jcontroller {var $ _ dB; // The following is the function _ construct () {parent ::__ construct () of the rsform controller (); $ this-> _ DB = jfactory: getdbo (); // obtain the database $ view = jrequest: getvar ('view', 'rsform '); // obtain the request // here I finally understand why the list of submitted forms cannot be displayed on the front-end. In the past, the view option here is only rsform, it may be because there is a problem with this version. I didn't buy the paid version. Now it's only for research purposes. If ($ view = 'rsform') $ this-> registerdefaulttask ('showform'); // register the default task $ Doc = & jfactory: getdocument (); $ doc-> addscript (JURI: Root (true ). '/components/com_rsform/assets/JS/script. JS '); // added the script. The next one will show it.} function CAPTCHA (){.....} Function plugin () {$ mainframe = & jfactory: getapplication (); $ mainframe-> triggerevent ('rsfp _ f_onswitchtasks ');} function showform () {........} function submissionsviewfile (){......} function ajaxvalidate (){......} function confirm (){......}}

After the controller is created, call the Controller to execute the task. The URL is defined as index. php? Option = com_hello & task = sometask. If no specific task is set, the default task 'display' is executed '. When the display task is executed, the 'view' variable determines what is displayed. Other common tasks are save, edit, and new )...

After the task is completed (for example, 'save'), the Controller usually decides the redirected page. The last line is used to determine the actual redirect page.

Essentially, the master entry point (hello. php) gives control to the Controller to execute the task specified in the request.

3. Create a view

Obtain the data to be displayed and inject it into the template. Use the JView: assignref method to inject data to the template. (Note: The key value passed to the assignref method (the first parameter) cannot start with an underscore ($ this-> assignref ('_ greeting', $ greeting ). In this case, the assignref method returns false and cannot inject the variable value into the template)

Source code of view com_rsform/views/rsform/view.html. php:

defined('_JEXEC') or die('Restricted access');jimport( 'joomla.application.component.view');class RSFormViewRSForm extends JView{    function display( $tpl = null )    {               parent::display($tpl);    }}

This seems to be a box with no content. I cannot understand it at present.

Function parsing:

Getvar () returns the given variable getword (), which is another version of the variable and directly receives the characters of A-Z. Do you understand?

You can force the source by setting the $ hash parameter (you can set the hash value to force the variable source ):

Mixed getvar (string $ name, [String $ default = NULL], [String $ hash = 'default'], [String $ type = 'none'], int $ mask)

§ String $ name: variable name

§ String $ default: default value when the variable does not exist

§ String $ hash: where the VaR shocould come from (post, get, files, Cookie, method)

§ String $ type: return type for the variable, for valid values see jfilterinput: Clean ()

§ Int $ mask: Filter

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.