I'm totally new to Joomla! I've never used it. I currently don't even know how to manage that content thing... The only thing that now interest me is to create a component that manages 4-6 SQL tables. I've already created administration classes for 2 tables but I want to know how does this hole naming convention works (MVC). During development I've had some 'class' not found errors. I don't want to tie controllers, models and views manually but I had to do it.
Let's check following example:
Component name: com_sdp
2 tables: members and groups
Using MVC model we should have at least 2 model-view-controller sets of classes: One for member and one for group.
It will also be nice to have 2 MVCs for listviews.
How should I name all 4 controllers?
If I name them like this:
Code: Select all
<?php
class MembersController extends JController
class MembersControllerMember extends MembersController
class GroupsController extends JController
class GroupsControllerGroup extends GroupsController
?>
Inside admin.sdp.php using following lines we determine which controller to choose basing on controller param value. (Example from tutorial).
Code: Select all
<?php
if($controller = JRequest::getWord('controller')) {
$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
if (file_exists($path)) {
require_once $path;
} else {
$controller = '';
}
}
// Create the controller
$classname = 'MembersController'.$controller;
$controller = new $classname( );
?>
The problem occurs when controller=groups. There is no such class: "MembersControllerGroup". Besides MembersControllerMember sounds so odd to me. So I've decided to have unified prefix AdminSDP_ for all my classes (just like the com_config component).
Code: Select all
<?php
class AdminSDP_ControllerMembers extends JController
class AdminSDP_ControllerMember extends MembersController
class AdminSDP_ControllerGroups extends JController
class AdminSDP_ControllerGroup extends GroupsController
...
if($controller = JRequest::getWord('controller','member')) {
$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
if (file_exists($path)) {
require_once $path;
} else {
$controller = '';
}
}
// Create the controller
$classname = 'AdminSDP_Controller'.$controller;
$controller = new $classname( );
?>
Now the default class bindings don't work. I think that is because of the prefix. So how should I call my classes? Should I use this default binding at all? I'm finally using just 2 controllers and I bind models and views manually. Can somebody share with me the Joomla! developers vision of this MVC thing. When I look at some core components of Joomla! they all look different and there are very few examples of MVC among them. Can somebody tell me why?
--
I hope this whole text is understandable - my English is not perfect.
Drapichrust