Elxis CMS Forum
Support => Elxis 4.x/5.x DEV => Topic started by: ksypolit on February 10, 2013, 13:25:05
-
Hello to all members of the community,
I am new to Elxis and i want to ask if there is available a guide for component development for Elxis 4.
I have the Elxis component guide for Elxis Aphrodite 2009 but i don't know if the techniques that are described in this guide are compatible with Elxis 4.
-
https://www.elxis.net/docs/
;)
-
Thanks for the reply Speck,
the are a lot of useful guides and advises in the new Elxis documentation site (such as Module development guide , Plugin development guide etc) but there is not a guide or tutorial for component development.
It will be very helpful if anyone can assist on this topic because i want to build a real estate component for Elxis 4 version.
-
Just for your information I have started a "template development guide" but I don't find free time to complete it. I will try to publish that guide as soon as possible.
As for the components, they are big applications and it is hard to write a full guide. Almost everything the documentation contains suits to a component. For instance you can use any Elxis library and helper in a component. The good thing is that ALL Elxis extensions have some very common things. For eample the installation file, the xml file, the parameters, the naming, etc, are common to all extensions. So, the modules development guide (https://www.elxis.net/docs/developers/tutorials/modules-guide.html) is very useful to components development too. What is different to components is that they have internal routing and use an MVC model (Model-View-Controller). The routing is required as a component can execute various tasks and display many different pages and the MVC model is a way to organize our code.
The main component's file (let's call it test.php) has a router class which extends the elxisRouter (https://www.elxis.net/docs/using-elxis/advanced-users/default-route-frontpage.html)
class testRouter extends elxisRouter {}
What this class does is to analyse the Elxis URI (https://www.elxis.net/docs/developers/libraries/elxisuri.html) segments and detect the proper controller and task for the user's request. The controller will call the model if it needs to get things from the database and finally load the view class to display the page's html. Take a look on how the built-in components are built. See a small component, it will be easier for you, don't mess with content which is larger.
Example
URL: www.example.com/test/places/london.html
Segments: array('places', 'london.html');
The router analyses these segments and finds out that the user wants to see information about a place (london).
The router now sets the task to "city" and the controller to "places" and includes the controller file (controller/places.php).
Inside the controller's file there is the "city" method (which is our task).
The router executes this task and then it is up to the controller/task to continue the page generation.
$places = new placesController();
$places->city();
Off course you can name and organize your files, controllers, tasks, methods, to anything you like.
-
Thank you very much for your reply.
-
this short guide is awesome.
actually i'm working on my own component also.
the magic for your own component is the abstract route method of someone subclass inherited fromelxisRouter
in my component, i added a middle/base class baseRouter, which inherited from elxisRouter,
the baseRouter class do the following important things:
1. to initialize the controller instance via the elxisRouter::segments, you can design any kinds of URL constructional, the only limitation is your imagination.
for mine, i madeit looks like: example.com/{component_name}/{controller_name}/{method_name}, and set the index as the default setting for both
{controller_name} and {method_name}, this is a traditional way.
2. to initialize the tpl instance, most people say this is the V of MVC,: TemplateView, a factory of \Rain\Tpl, setting cache, template dir, etc,
I prefer a template engine, smarty or RainTpl, to the raw php style view, which is used by Elxis also.
3. to initialize the model
that's all for me.
Just for your information I have started a "template development guide" but I don't find free time to complete it. I will try to publish that guide as soon as possible.
As for the components, they are big applications and it is hard to write a full guide. Almost everything the documentation contains suits to a component. For instance you can use any Elxis library and helper in a component. The good thing is that ALL Elxis extensions have some very common things. For eample the installation file, the xml file, the parameters, the naming, etc, are common to all extensions. So, the modules development guide (https://www.elxis.net/docs/developers/tutorials/modules-guide.html) is very useful to components development too. What is different to components is that they have internal routing and use an MVC model (Model-View-Controller). The routing is required as a component can execute various tasks and display many different pages and the MVC model is a way to organize our code.
The main component's file (let's call it test.php) has a router class which extends the elxisRouter (https://www.elxis.net/docs/using-elxis/advanced-users/default-route-frontpage.html)
class testRouter extends elxisRouter {}
What this class does is to analyse the Elxis URI (https://www.elxis.net/docs/developers/libraries/elxisuri.html) segments and detect the proper controller and task for the user's request. The controller will call the model if it needs to get things from the database and finally load the view class to display the page's html. Take a look on how the built-in components are built. See a small component, it will be easier for you, don't mess with content which is larger.
Example
URL: www.example.com/test/places/london.html
Segments: array('places', 'london.html');
The router analyses these segments and finds out that the user wants to see information about a place (london).
The router now sets the task to "city" and the controller to "places" and includes the controller file (controller/places.php).
Inside the controller's file there is the "city" method (which is our task).
The router executes this task and then it is up to the controller/task to continue the page generation.
$places = new placesController();
$places->city();
Off course you can name and organize your files, controllers, tasks, methods, to anything you like.
-
I think you dont need the baseRouter, but it's ok, I wont argue on that.
If your component needs some extra repeated functionality you can create a helper class or the base controller may contain common methods.
In what I disagree with you is placing controller and method names exactly as is in the URL. Also don't use index.html in the URLs as you will face problems.
-
thanks datahell.
exactly, elxisRouter is not necessary , as i know, Elxis require a class which implemented the interface with a method called route .
but elxisRouter is a well/easy beginning.
about the url and the method mapping, lots of people call it url routing, maybe my imagination is limited by something as said "the only limitation is your imagination" :)
I think you dont need the baseRouter, but it's ok, I wont argue on that.
If your component needs some extra repeated functionality you can create a helper class or the base controller may contain common methods.
In what I disagree with you is placing controller and method names exactly as is in the URL. Also don't use index.html in the URLs as you will face problems.
-
exactly, elxisRouter is not necessary...
Id didn't said that, a class to extend the elxisRouter is one of a few requirements an Elxis component should have. I said that it is not needed your custom "baseRouter".
Your component's main php file should have something like this:
mycomponentRouter extends elxisRouter {
public function __construct() {}
public function route() {} //this is where you analyze URI segments and determine the controller and method to call
}