In this article we discuss the outlines of building a custom backend Joomla component structured on the MVC model.
The details and complete code are covered in the members area
We make a component that will write text to a text file. The user will enter the text in the component administrator interface. We shall name the component mytext. We will use our localhost installation to develop the component.
Step 1
Make a folder called com_mytext in the admin components folder.
administrator/components /com_mytext
Step 2
Create the component entry file. This is a php file with the name admin.mytext
Our model file will deal with the file handling. We extend the standard JModel class. In this case we will use PHP file handling routines to open our text file and write new text to the file
Example
class mytextModelmytext extends JModel
function getFile() { $file=JPATH_SITE.DS."mytext.txt"; $fh = fopen($file, 'r'); $this->_text=fread($fh, filesize($file));
The template view file displays the output and accepts input from the user. In our eaxmple we use an html form for this. The form will display the current text and allow the user to enter the new text. The form action method will invoke the corresponding action from the controller file.
Step 7
Create the install xml file
administrator/components/com_mytext/mytext.xml
Here we tell the Joomla installer what files exist for this component
In our example we will manually install this component.
Step 8
After testing your component locally, FTP the folders and files to the actual Joomla site
Step 9
Register the component in the database (jos_components)
That concludes this article on creating a custom back-end Joomla MVC component.