working through MVC tutorial from joomla web page

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
jimiwa
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Sat Jan 30, 2010 11:00 pm

working through MVC tutorial from joomla web page

Post by jimiwa » Thu Mar 18, 2010 9:26 pm

I'm trying to work through the MVC tutorial from the documentation->developers
section of the Joomla web page. I'm wanting to put together all the code and check
to see that it works correctly. Does anyone know if all of the code is 100% correct
or might there be a minor typing error in these 5 articles? Furthermore, I am having
trouble understanding what directory every file goes in, as it doesn't explicitly say
exactly what directory every file goes in in the tutorial, although this may be implied
due to context but I don't get it.
Up to this point, I have the following files:

controller.php
default.php
hello.php
view.html.php
/models/hellos.php
/views/hellos/view.html.php
/views/hellos/tmpl/default.php
/views/hellos/tmpl/form.php

and this is up to the point in part 5 "creating the table class" but not including it.

It says for one file at this point:

"This file should be called hello.php and it will go in a directory called tables in the administrator section of our component."

What is the administrator section of the component exactly? I have read through the tutorial
once but sometimes things don't sink in, and I don't know specifically which folder this is in.

Also, the functions "save", "store", "delete", "remove", and "cancel" - do these all go in the hello model? I assume this is the file /models/hellos.php - am I correct?

tuum
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 207
Joined: Fri Sep 19, 2008 12:03 am
Location: Sydney, Australia
Contact:

Re: working through MVC tutorial from joomla web page

Post by tuum » Fri Mar 19, 2010 4:09 am

jimiwa wrote:I'm trying to work through the MVC tutorial from the documentation->developers
section of the Joomla web page. I'm wanting to put together all the code and check
to see that it works correctly. Does anyone know if all of the code is 100% correct
or might there be a minor typing error in these 5 articles?
There's always a chance for human error, but I would suspect that these tutorials are pretty good as a lot of people use them . If you find an error, just add a comment on the discussion tab and someone should correct it.
jimiwa wrote: Furthermore, I am having
trouble understanding what directory every file goes in, as it doesn't explicitly say
exactly what directory every file goes in in the tutorial, although this may be implied
due to context but I don't get it.
Up to this point, I have the following files:

controller.php
default.php
hello.php
view.html.php
/models/hellos.php
/views/hellos/view.html.php
/views/hellos/tmpl/default.php
/views/hellos/tmpl/form.php

and this is up to the point in part 5 "creating the table class" but not including it.

It says for one file at this point:

"This file should be called hello.php and it will go in a directory called tables in the administrator section of our component."

What is the administrator section of the component exactly? I have read through the tutorial
once but sometimes things don't sink in, and I don't know specifically which folder this is in.
There are basically two places on a Joomla site where a component has files, one for the back end
/administrator/components/com_insertYourComponentName/

and one for the front end
/components/com_insertYourComponentName/

Within each of these will be a number of folders, for example views, tables, models, helpers etc.

So in this case the hello.php file would be in
/administrator/components/com_insertYourComponentName/tables/hello.php
jimiwa wrote: Also, the functions "save", "store", "delete", "remove", and "cancel" - do these all go in the hello model? I assume this is the file /models/hellos.php - am I correct?
Yes, these functions should be in the model associated with the current view, in this case
/administrator/components/com_insertYourComponentName/models/hellos.php

regards

Tim
Tim Plummer - Tweet @bfsurvey

becyn
Joomla! Explorer
Joomla! Explorer
Posts: 458
Joined: Mon Aug 11, 2008 1:16 am
Location: Newburgh Ny , USA
Contact:

Re: working through MVC tutorial from joomla web page

Post by becyn » Fri Mar 19, 2010 3:02 pm

A component folder in is placed inside the component folder found in the Admin side and the site side.
look inside the existing components folder and you will see various com_* folders which are the name folders for those components.
So, all of this:
controller.php
hello.php
/models/hellos.php
/views/hellos/view.html.php
/views/hellos/tmpl/default.php
/views/hellos/tmpl/form.php
( I removed the extraneous files in root. the view.html.php and default belong where shown above.)

is in the folder :
components/com_hellos
BTW, i think the the entry php has to bear the same name as the component.
If the component name is hellos, that file should be hellos.php or it won't work.
Learn something new every day!

ramdesh
Joomla! Apprentice
Joomla! Apprentice
Posts: 49
Joined: Mon Jan 04, 2010 4:20 pm
Location: Boralesgamuwa, Sri Lanka
Contact:

Re: working through MVC tutorial from joomla web page

Post by ramdesh » Fri Mar 19, 2010 4:16 pm

jimiwa wrote:
"This file should be called hello.php and it will go in a directory called tables in the administrator section of our component."

What is the administrator section of the component exactly? I have read through the tutorial
once but sometimes things don't sink in, and I don't know specifically which folder this is in.
When DEVELOPING the component before it is installed, you should have two folders, site and admin. The MVC tutorial is mostly concerned with developing an admin back end. So most of the files,especially from parts 5 and 6, go in the folder named 'admin'. For this, your xml installer file should have the following admin file copy section IN ADDITION to the front-end site file copy section defined earlier in the tutorial:

Code: Select all

<files folder="admin">
  <filename>controller.php</filename>
  <filename>default.php</filename>
  <filename>hello.php</filename>
  <filename>view.html.php</filename>
  <filename>/models/hellos.php</filename>
  <filename>/views/hellos/view.html.php</filename>
  <filename>/views/hellos/tmpl/default.php</filename>
  <filename>/views/hellos/tmpl/form.php</filename>
  <filename>/tables/hello.php</filename>
</files>

jimiwa wrote:Also, the functions "save", "store", "delete", "remove", and "cancel" - do these all go in the hello model? I assume this is the file /models/hellos.php - am I correct?
Yes quite correct. You can name these functions any way you want.

Hope this helps!!! And good luck!!!
Temporary catatonic, madman on occassion
Twitter: http://twitter.com/rami_desh
My Latest Joomla dev project: http://joomlacode.org/gf/project/smssubscribe1/

ramdesh
Joomla! Apprentice
Joomla! Apprentice
Posts: 49
Joined: Mon Jan 04, 2010 4:20 pm
Location: Boralesgamuwa, Sri Lanka
Contact:

Re: working through MVC tutorial from joomla web page

Post by ramdesh » Fri Mar 19, 2010 4:18 pm

Oh and BTW when you install the component using the Joomla installer, the files listed under the <files folder="admin"> tag in the xml file will automatically get installed to /administrator/components/com_insertYourComponentName/tables/hello.php
Cheers!
Temporary catatonic, madman on occassion
Twitter: http://twitter.com/rami_desh
My Latest Joomla dev project: http://joomlacode.org/gf/project/smssubscribe1/

becyn
Joomla! Explorer
Joomla! Explorer
Posts: 458
Joined: Mon Aug 11, 2008 1:16 am
Location: Newburgh Ny , USA
Contact:

Re: working through MVC tutorial from joomla web page

Post by becyn » Sat Mar 20, 2010 3:14 am

One note about model method naming conventions.
While it is true that you CAN name those functions whatever you wish, but it is more efficient if you name the functions with the prefix "get", ie; "getInfo(), etc, when using them in the view.
This enables the use of the JView::get() method to call individual model functions without loading the entire model.
If your model funtion is named getInfo(), you call it in the view code like this:

Code: Select all

$info = &$this->get('info');
Learn something new every day!

ramdesh
Joomla! Apprentice
Joomla! Apprentice
Posts: 49
Joined: Mon Jan 04, 2010 4:20 pm
Location: Boralesgamuwa, Sri Lanka
Contact:

Re: working through MVC tutorial from joomla web page

Post by ramdesh » Sat Mar 20, 2010 3:26 am

Ah yes, interesting point that I forgot to put in. Cheers, becyn! :)
Temporary catatonic, madman on occassion
Twitter: http://twitter.com/rami_desh
My Latest Joomla dev project: http://joomlacode.org/gf/project/smssubscribe1/

jimiwa
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Sat Jan 30, 2010 11:00 pm

Re: working through MVC tutorial from joomla web page

Post by jimiwa » Mon Mar 22, 2010 12:34 am

So for the controller, hello.php in part 6, does it go in the
com_hellos directory of the administrator section or does it
go in the subdirectory controllers inside of com_hellos?

becyn
Joomla! Explorer
Joomla! Explorer
Posts: 458
Joined: Mon Aug 11, 2008 1:16 am
Location: Newburgh Ny , USA
Contact:

Re: working through MVC tutorial from joomla web page

Post by becyn » Tue Mar 23, 2010 2:17 pm

Put it in the controllers sub directory , if you have one.
Most of the time there is only one controller used so it is in the com_componetName directory with no subdirectory.
there seems to be duelling tutorials on the documentation site.
This one makes more sense to me.(it's also the more up to date one)
http://docs.joomla.org/Developing_a_Mod ... t_-_Part_1
The old one is very confusing and presented in a piece-meal fashion that does not show how every thing works together.
Defining a funtion is one thing, calling it is another!
Learn something new every day!

jimiwa
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Sat Jan 30, 2010 11:00 pm

Re: working through MVC tutorial from joomla web page

Post by jimiwa » Tue Mar 23, 2010 10:50 pm

ramdesh wrote:
jimiwa wrote:
"This file should be called hello.php and it will go in a directory called tables in the administrator section of our component."

What is the administrator section of the component exactly? I have read through the tutorial
once but sometimes things don't sink in, and I don't know specifically which folder this is in.
When DEVELOPING the component before it is installed, you should have two folders, site and admin. The MVC tutorial is mostly concerned with developing an admin back end. So most of the files,especially from parts 5 and 6, go in the folder named 'admin'. For this, your xml installer file should have the following admin file copy section IN ADDITION to the front-end site file copy section defined earlier in the tutorial:

Code: Select all

<files folder="admin">
  <filename>controller.php</filename>
  <filename>default.php</filename>
  <filename>hello.php</filename>
  <filename>view.html.php</filename>
  <filename>/models/hellos.php</filename>
  <filename>/views/hellos/view.html.php</filename>
  <filename>/views/hellos/tmpl/default.php</filename>
  <filename>/views/hellos/tmpl/form.php</filename>
  <filename>/tables/hello.php</filename>
</files>

jimiwa wrote:Also, the functions "save", "store", "delete", "remove", and "cancel" - do these all go in the hello model? I assume this is the file /models/hellos.php - am I correct?
Yes quite correct. You can name these functions any way you want.

Hope this helps!!! And good luck!!!
I've gone through the entire tutorial but I didn't see anywhere where
we were suppossed to have quite a few of the files you listed.
Maybe it's my problem.

Anyways,, where does it say to put controller.php and default.php
in the administrator directory? I don't have a table directory. I don't have
a view.html.php file in /views/hellos. I don't have default.php in views/hellos/tmpl
either.

Furthermore, some of these files are listed twice. Are these the same file duplicated
or two different files with the same name? I thought I went through the whole
tutorial and had them all covered, but apparently not. I'm getting really confused here.
Are the two view.html.php files the same file? What the two default.php files?

Also, what is the index.html file in the administrator directory that's listed in the earlier
xml file?
Is there just one xml file for the completed tutorial project, or is there one in the administrator
directory too? I'm assumming there's just one in the regular directory.

Thanks for everyone's help so far. I'm hoping I'll eventually get this right.

becyn
Joomla! Explorer
Joomla! Explorer
Posts: 458
Joined: Mon Aug 11, 2008 1:16 am
Location: Newburgh Ny , USA
Contact:

Re: working through MVC tutorial from joomla web page

Post by becyn » Thu Mar 25, 2010 2:36 pm

've gone through the entire tutorial but I didn't see anywhere where
we were suppossed to have quite a few of the files you listed.
Maybe it's my problem.

Anyways,, where does it say to put controller.php and default.php
in the administrator directory? I don't have a table directory. I don't have
a view.html.php file in /views/hellos. I don't have default.php in views/hellos/tmpl
either.
With programming, sometimes it's best to do some experimentation. I can understand your confusion, since there are some different ways to do the same thing, but in some other cases, there is a specific way.
You no longer have to list all of the files in the XML , just the folders.
The table directory is only needed (along with the table files) if you are using JTable for database access.
You DO need to have view.html.php in views/hellos and default.php (your page template) in views/hellos/tmpl.
A very basic Joomla component directory hierarchy is;
/components
/com_mycomponent
/mycomponent.php (entry point code)
/tables (optional)
/models
/viewname.php (this associates model with view)
/views
/viewname
/view.html.php ( view formatting code)
/tmpl
/default.php ( default template for viewname)
/controllers
/mycomponent.php (base controller)
/viewname.php (associates this controller with viewname)

This is a bare bones setup to make it work. I don't want add any more to further confuse the issue . There are lots of other things that can and should be added to make it an installable component, etc, but this is the basic structure.
Learn something new every day!

ramdesh
Joomla! Apprentice
Joomla! Apprentice
Posts: 49
Joined: Mon Jan 04, 2010 4:20 pm
Location: Boralesgamuwa, Sri Lanka
Contact:

Re: working through MVC tutorial from joomla web page

Post by ramdesh » Thu Mar 25, 2010 4:40 pm

Sorry, the in that post you quoted, the 'default.php' file in the base admin folder shouldn't be there. I was just trying to show where the table file should go, so I simply copied the list you had created earlier without looking. Follow becyn's guidance and you should get to the bottom of it eventually.
Good Luck!!


BTW becyn, I take it from your inclusion of a 'controllers' directory that you would use multiple controllers. Is there any specific advantage to this? I generally use a lot of models and a single controller which I use to manipulate them all. But then again, the entry point generally has the ability to get a controller name from the query string right? So does that imply that we're supposed to use multiple controllers?

Thanks.
Temporary catatonic, madman on occassion
Twitter: http://twitter.com/rami_desh
My Latest Joomla dev project: http://joomlacode.org/gf/project/smssubscribe1/

becyn
Joomla! Explorer
Joomla! Explorer
Posts: 458
Joined: Mon Aug 11, 2008 1:16 am
Location: Newburgh Ny , USA
Contact:

Re: working through MVC tutorial from joomla web page

Post by becyn » Thu Mar 25, 2010 8:09 pm

BTW becyn, I take it from your inclusion of a 'controllers' directory that you would use multiple controllers. Is there any specific advantage to this? I generally use a lot of models and a single controller which I use to manipulate them all. But then again, the entry point generally has the ability to get a controller name from the query string right? So does that imply that we're supposed to use multiple controllers?
No,you can use just one controller, but if you need more than one for some reason, use the folder.
Some components have other folders, such as helper and image, depending on the need.
I didn't want to go too crazy with the example, lest I muddy the waters...but I guess i managed to do that anyway. :laugh:
Learn something new every day!

ramdesh
Joomla! Apprentice
Joomla! Apprentice
Posts: 49
Joined: Mon Jan 04, 2010 4:20 pm
Location: Boralesgamuwa, Sri Lanka
Contact:

Re: working through MVC tutorial from joomla web page

Post by ramdesh » Fri Mar 26, 2010 4:47 pm

becyn wrote:I didn't want to go too crazy with the example, lest I muddy the waters...but I guess i managed to do that anyway. :D
As long as jimiwa isn't confused, it's ok right?
Thanks for your help!

jimiwa, I would suggest building the Hello World component again from scratch and seeing if you run in to any problems. We're always here to help you. Try to experiment with the code a bit. Try creating tables with different names, having multiple table files in the tables folder, multiple view files, forms etc after you've done the Hello World thing. Good Luck!
Temporary catatonic, madman on occassion
Twitter: http://twitter.com/rami_desh
My Latest Joomla dev project: http://joomlacode.org/gf/project/smssubscribe1/


Locked

Return to “Joomla! 1.5 Coding”