Creating a Nennius Component Now that we have setup our basic web application, it is time to consider the data we will be managing. Since our example application is intended only to manage news releases for a corporate website, our component will be relatively basic. There are a variety of ways to create Nennius components, some simple and some complex. All component logic can be contained within a single file, or split apart into multiple files. The latter is recommended in the Nennius documentation. So for our component we will split our logic into three files, each described below: /news/index.php - instantiates news component - this is our entry-point file At first, this may seem overly complicated. However it is a good development habit to design projects to be easily scalable. By splitting these three areas of logic into their own files, we will make upgrading and enhancing our system (described in Part 3 of this article) a much easier task. Furthermore, creating each file in its own descriptive folder area will result in a lot less clutter for larger Nennius projects. Defining the Entry-PointSince our application will only be managing one type of data, we have chosen to name our entry point 'index.php'. An entry-point file simply includes and instantiates our component class, so defining it will be relatively simple: <?php As you can see, all our index file does is include our component file (along with the class it extends) and then instantiates it by passing it a reference to our descriptor file. Both the component and descriptor files have been mentioned briefly, but let's now take a closer look at each. The Descriptor FileThe descriptor file is where we store information pertaining to the component as a whole. This information ranges from the name of the component (displayed in the browser's title area) to the name of the DB table containing our component's data. This is different than the component file, as it does not describe the data's attributes, merely its overall behavior. Our descriptor file will contain the following: <?php
blog comments powered by Disqus |