The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Mon Feb 04, 2008 10:22 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Feb 22, 2007 4:07 pm
Posts: 21
Hi,

I discovered how joomla 1.5 sees the MVC concept.
I found it completely messy. I cannot see what really improves efficency.
I also work on other framework like Django (python) and RoR (ruby) and MVC is really clear (one file per function).

Here we have files for admin, files for modeling, files for views (one file per view), files for function, each one organized in differents folders.
I think that Joomla 1.5 will make me stop developping on Joomla, I've read the Learning Joomla Extension Development Book and tried to develop new components. I was waiting more on this version and I'm a bit disappointed.
Moreover, it's always boring to draw preety URLs, it's possible but a bit rigid in my opinion.
I cannot see what is the plus of MVC here, MVC seems to be in vogue.

Just my opinion about it, hope you'll share or not this.


Top
 Profile  
 
PostPosted: Mon Feb 04, 2008 10:37 am 
User avatar
Joomla! Ace
Joomla! Ace

Joined: Fri Aug 12, 2005 2:45 am
Posts: 1961
Location: Toowoomba, Australia
Hi tynmar

Thanks for your comments.  Let's try and find some common ground from which to work.  Say Joomla! was built on Django or RoR (pick your favourite), what would the file structure look like under /components/com_foobar if you were to design a simple component and very roughly what do those files do?  If you can explain that a little then maybe I can shed some light on why we've chosen to do some things the way we have (a lot of which has to do with allowing template designers to override stuff or assigning stuff to a menu).

Thanks in advance.

_________________
Andrew Eddie - Tweet @AndrewEddie
<><
http://learn.theartofjoomla.com - Joomla 2.5 training videos!
http://www.kiva.org/team/joomla - Got Joomla for free? Pay it forward and help fight poverty.


Top
 Profile  
 
PostPosted: Mon Feb 04, 2008 11:02 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Feb 22, 2007 4:07 pm
Posts: 21
Yes, of course !  :D
I love Django Philosophy.

Maybe, a real template engine for components maybe clearer for designers (smarty is a good one).
Then we could have (from root)
/templates
/templates/base (with installed site template)
/templates/components
/templates/components/com_foobar (here we could find all our templates, we can organize as we want because simple component doesn't always need 3 or 4 folders to view and modify a list)

/components/com_foobar may contain

model.php
A clear view of our database structure in a file.
You could create classes
class fooBar extends somethingInJoomlaAPI
{
var $id = null; // impossible to tell it's an integer ? a varchar ? ...
}

class fooBarComments extends somethingInJoomlaAPI
{
var $id = null; // impossible to tell it's an integer ? a varchar ? ...
}

?>

controller.php

include('model');
switch($foo){
case 'bar':
doSomething();
break;
}


function doSomething(){
query...() loop()...
display('common.tpl'); (this is in the first template folder)
or redirect('somewhere');
}

?>

You want to design friendly URL, Joomla cannot include regexp for urls ? I have to rewrite my htaccess ?
a file called
/component/com_foobar/urls.php
would be great.


I think that things are not always clear with a real MVC model. Nobody forces anybody to reproduce a code structure.
As you can see, I didn't show exactly a true MVC, It's more a MTV model (Model-Template-View).
After all, each one have to work where he feels it's a right way. I don't think Joomla 1.5 improves programming speed or organization.


Top
 Profile  
 
PostPosted: Mon Feb 04, 2008 11:55 am 
User avatar
Joomla! Ace
Joomla! Ace

Joined: Fri Aug 12, 2005 2:45 am
Posts: 1961
Location: Toowoomba, Australia
tynmar wrote:
/templates/components/com_foobar (here we could find all our templates, we can organize as we want because simple component doesn't always need 3 or 4 folders to view and modify a list)


Compare that with the Beez template.  Look in:
/templates/beez/html/com_content/(view name)

tynmar wrote:
/components/com_foobar may contain

model.php


In Joomla! we tend to separate the Model, from the Table API, and we have one model per file, and one table per file.

In a mega-component like com_content we will have a table for articles, for categories and for sections (actually we stick those in the core libs, but that's beside the point).  We generally have a model file for dealing with each type of view.  So, we'd have a model that dealt with working with categories, and one that dealt with working just with articles.  We have a base class called JModel that does a lot of work for you.  JTable is just a rehash of the old mosDBTable class with a few extra perks.


tynmar wrote:
A clear view of our database structure in a file.
You could create classes
class fooBar extends somethingInJoomlaAPI
{
var $id = null; // impossible to tell it's an integer ? a varchar ? ...
}

class fooBarComments extends somethingInJoomlaAPI
{
var $id = null; // impossible to tell it's an integer ? a varchar ? ...
}

?>

That's a very Drupal way of doing things (and there's nothing wrong with that).  However, in Joomla we have no concept of a base "node" or "thing" ... well, except JObject I guess.  So in the above example if you are dealing with a Model, you do:

class fooBarModelComments extends JModel

and a view:

class fooBarViewComments extended JView

tynmar wrote:
controller.php

include('model');
switch($foo){
case 'bar':
doSomething();
break;
}


function doSomething(){
query...() loop()...
display('common.tpl'); (this is in the first template folder)
or redirect('somewhere');
}

?>


For the controller I took a note out of RoR's methodology.  We don't use the switch statements anymore.  Your controller looks something like this:

class fooBarController extends JController
{
  function bar()
  {
    // do something
  }
}

$controller = new fooBarController;

$controller->execute( 'bar' );
$controller->redirect();
?>

You pass a task into the controller and the controller looks for a function of that name.  I'm actually really happy with the controller - it's a pretty neat class and it draws heavily on the other paradigms you quoted.  The controller also has helper methods for doing redirection.

tynmar wrote:
You want to design friendly URL, Joomla cannot include regexp for urls ? I have to rewrite my htaccess ?
a file called
/component/com_foobar/urls.php
would be great.


You would use a file called:
/components/com_foobar/router.php

Basically it accepts an array and you have to pass one back - knock yourself out on the desired logic you want.

Hope this helps a little.  You don't have to agree with it, but we have based the whole system heavily on the ruby and python examples and there is compromise involved - I'll grant you that.  However, if you want Joomla to be Cake, or follow RoR religiously, you won't find that and that's not really a goal we ever set ourselves.  It's more of a hybrid system that tries to find the line of best fit among many competing conditions and constraints.

_________________
Andrew Eddie - Tweet @AndrewEddie
<><
http://learn.theartofjoomla.com - Joomla 2.5 training videos!
http://www.kiva.org/team/joomla - Got Joomla for free? Pay it forward and help fight poverty.


Top
 Profile  
 
PostPosted: Mon Feb 04, 2008 12:47 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Feb 22, 2007 4:07 pm
Posts: 21
Thank you for this enlightenment, I've read the entire book dedicated to developpement in Joomla 1.5.
The Joomla API is simply great and it's a good thing that we can also continue to program like before :
basicly :
components/com_foobar/foobar.php
components/com_foobar/foobar.class.php
components/com_foobar/foobar.html.php

>> find the line of best fit among many competing conditions and constraints.
I agree Joomla developpers made a excellent job, Joomla becomes one of the most amazing php project.

I tried also RoR, I just didn't like the separation of packages
/models/foobar
/views/foobar

In Django You have
/foobar/model
/foobar/view
/foobar/form
/foobar/url
more readable i.m.o.

I'm falling in love with Django  :-* like I falled in love with Joomla 2 years ago  ;D
I have to code more and more with this new concept, maybe it's too new and I have to change my habits..


Top
 Profile  
 
PostPosted: Mon Feb 04, 2008 2:58 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Fri Dec 08, 2006 7:01 pm
Posts: 215
tynmar wrote:
I tried also RoR, I just didn't like the separation of packages
/models/foobar
/views/foobar

In Django You have
/foobar/model
/foobar/view
/foobar/form
/foobar/url
more readable i.m.o.


I don't think we can find a better example of how workstyle influences our choices. I saw the same two options, and I much preferred the Rails way. You can find the same differences of approach in the organization of CSS files: one person will organize the CSS selectors by the id/class they apply to (#main, then #main p, #main a, etc., followed by #sidebar, #sidebar p, #sidebar h3, and so on through the file) while the next person will organize them by the tags they style (p styles, followed by #main p, #sidebar p, then h3 styles followed by #main h3, #sidebar h3, and so on). Both are sure their way is the best.

And both are correct. From your preference I would suspect you work on one object at a time, getting the model, the view, and the controller right for it, then move on to the next object, etc. Me, I tend to work in "model mode", firguring out what I need from every model in a project first, then I move on to all the controllers, all the views. Hence each of us prefers the organization that favors our workstyle.

Whenever we work inside a given framework, we have to adopt the "thinking mode" (for lack of a better term) the framework favors. For some, working in the Joomla "thinking mode" is uncomfortable. For me, working in Drupal "thinking mode" is uncomfortable. But I do it, when circumstances or clients demand it.

Personally, I *love* developing in Rails. It has rapidly ascended to #1 on my charts. That Joomla has borrowed concepts from it makes it easier for me to find my way around inside it; it makes it harder for you, because it runs contrary to your workstyle. I thought the old organization of files was harder to work with than the current one. I'm finding it much easier to track down and fix what I see as problems in the core modules now than I ever did before. (Note: Where I can I use template overrides, but sometimes I can't do that and have to twiddle the modules themselves. There's a mod-mainmenu issue I'm tracking right now, for example, that can't be fixed with a template override. I wouldn't have even considered doing this in 1.0.x.)

That's not a value judgement. It doesn't make either Joomla, Rails, Django, you, or I superior or inferior. I understand your discomfort with some of the choices made, and it's great to get them out and talk about them. Until this thread, for example, I hadn't realized why some of the new arrangements seemed so intuitively right to me, and why others just kept slipping out of my mental grasp. Awareness is half the battle; now I have a better idea where to start understanding those, so thanks for starting this thread.


Top
 Profile  
 
PostPosted: Mon Feb 04, 2008 3:35 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Feb 22, 2007 4:07 pm
Posts: 21
> That's not a value judgement
Of course not. Joomla is based on community, so I think it's important to talk about what developpers feel on this evolution. If developpers don't have feedback, they don't know.

> I hadn't realized why some of the new arrangements seemed so intuitively right to me
So there are good points  :laugh: !
My point of vue is quite similar to you but we think different ways for what is confortable. So that's ok ! because we can choose our tools.
In the case of Ruby, I saw it's a little bit slow for apps with thousands users  and its library is not as rich as python's.

> But I do it, when circumstances or clients demand it.
Let's work right now ! :)

Excuse my poor english, je fais ce que je peux.


Top
 Profile  
 
PostPosted: Mon Feb 04, 2008 4:11 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Fri Dec 08, 2006 7:01 pm
Posts: 215
Your english is far better than my french. Je parle français seulement.


Top
 Profile  
 
PostPosted: Mon Feb 04, 2008 4:16 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Feb 22, 2007 4:07 pm
Posts: 21
Because I installed the last Joomfish Brain edition.  :D


Top
 Profile  
 
PostPosted: Mon Feb 04, 2008 9:52 pm 
User avatar
Joomla! Ace
Joomla! Ace

Joined: Fri Aug 12, 2005 2:45 am
Posts: 1961
Location: Toowoomba, Australia
The reason we've gone for putting "things" in folders, that is:

/com_foobar/models/article.php
/com_foobar/models/category.php
/com_foobar/tables/article.php

is that we have a intelligence behind the getInstance method that looks at multiple paths.  You can do things like:

JModel::addIncludePath( $path1 );
JModel::addIncludePath( $path2 );

and then when you try and find a model:

$model = JModel::getInstance( 'article', 'FoobarModel' );

It looks through the list of sources to find the correct model.  This allows you to very easily pull models from "other" extensions.

Likewise for views, the folder hierarchy is tightly coupled with the way the new menu manager is done (go to the menu manager and click New).

What we have to remember is there is a difference between academic and practical programming.  I would wager that if you had to port Joomla! to Rails, then you would see an increase in complexity simply because of the way you need to support the UI.  Not suggesting we still can't improve things, but Joomla! is more like a framework about which you can run "many" MVC applications (ie, extensions/components).  That's something I haven't seen well addressed in Cake for example.  Some of the issues you'd need to consider are, ok, if we change the way the views work, how would you still allow the menu manager to operate with the same flexibility.  Some things to think about.

_________________
Andrew Eddie - Tweet @AndrewEddie
<><
http://learn.theartofjoomla.com - Joomla 2.5 training videos!
http://www.kiva.org/team/joomla - Got Joomla for free? Pay it forward and help fight poverty.


Top
 Profile  
 
PostPosted: Fri Feb 08, 2008 2:24 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Feb 22, 2007 4:07 pm
Posts: 21
I tried again to adapt myself to this method but I always cannot feel confortable with it.
This system is really well elaborated, we can see that many Joomla developpers spent a lot of time (and maybe coffee, cigaretts...) on this cms.

What really cool is the direct access to the section / menu / category ... tables

$categorie =& JTable::getInstance('category');
$categorie->load($cat_id);

It's very simple. But I had to hack the sections table and add a col named "zui".
This method can't access to my col "zui" :

$section =& JTable::getInstance('section');
$section->load($section_id);
echo $section->title;
-->> Ma jolie section
echo $section->published;
-->> 1
echo $section->zui;
-->>

Where can I find the section Class to add my zui var ?
Thanks a lot  ;)


Top
 Profile  
 
PostPosted: Fri Feb 08, 2008 8:35 pm 
User avatar
Joomla! Ace
Joomla! Ace

Joined: Fri Aug 12, 2005 2:45 am
Posts: 1961
Location: Toowoomba, Australia
JTable section is in
/libraries/joomla/database/table/section.php

However, I wouldn't hack the core table - because this will get blown away on the next Joomla update.

Rather, do this in your own component:

/components/com_myblog/tables/section.php

Code:
jimport( 'joomla.database.table.section' );

class MyBlogTableSection extends JTableSection
{
  var $zui;
}

// then in your code

JTable::addIncludePath( JPATH_COMPONENT.DS.'tables' );

$table = JTable::getInstance( 'Section', 'MyBlogTable' );


J 1.5 was built specfically with "extension" in mind so that you don't have to hack the core code anymore.  Need more out of a class - just extend it.

_________________
Andrew Eddie - Tweet @AndrewEddie
<><
http://learn.theartofjoomla.com - Joomla 2.5 training videos!
http://www.kiva.org/team/joomla - Got Joomla for free? Pay it forward and help fight poverty.


Top
 Profile  
 
PostPosted: Sun Feb 10, 2008 6:27 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Feb 22, 2007 4:07 pm
Posts: 21
You're absolutly right  ;)
Thank you for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 



Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group