Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How the Joomla MVC will call the functions in a custom component...?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  13 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
fornandakishore  
View profile  
 More options Jul 27 2012, 11:59 pm
From: fornandakishore <fornandakish...@gmail.com>
Date: Sat, 28 Jul 2012 09:29:20 +0530
Local: Fri, Jul 27 2012 11:59 pm
Subject: How the Joomla MVC will call the functions in a custom component...?

Hello to all,
How the Joomla MVC will call the functions in a custom component...?

I am creating some custom components in Joomla but seems I am missing
something on the code.

Here are my doubts..

1. When I create a menu link the menu appears ex: www.site.com/
index.php?option=com_mycom&view=default&layout=mylayout

=> I need to know how this will execute. It seems to me first it is calling
view.html.php => display() function, here when it will go to controller
task functions.

=> if the menu link is like the above one then my controller functions are
not executed. Here how to call controller task functions from view.html.php

2. I am creating links in custom components like this : www.site.com/
index.php?option=com_mycom&task=mytask

=> When we click on this link, first it is going to controller mytask
function and from that task to view.html.php function and their it is
calling specified view.

Here I am getting confusion, how the MVC work flow will be when the links
are created by menus ?

Sample code :

[code]

My controller code is like this :

class mycomMycontroller extends JController {

function display () {
// some code

}

function mytask () {
$view = &$this -> getView('MyView', 'html');
$view -> setLayout('bookings');
$view -> Bookings();

}
}

My View.html.php file is like this :

function display () {
// some code

}

function Bookings ($tpl = null) {

$model =& JModel::getInstance('MyView', 'MyComModel');
$alert =& $model->fetchData();
$this -> assignRef('alert', $alert);
parent::display($tpl);

}

[/code]

suppose if I create a external menu link like : www.site.com/
index.php?option=com_mycom&task=mytask then it is going smoothly to the
mytask() function and it fetches the layout with values successfully..

But if I create a menu using menu manager then that link is like this :
www.site.com/index.php?option=com_mycom&view=default&layout=bookings
And in this situation it is going to the display () function in
view.html.php only...and not to controller mytask() or not to view.html
bookings()

 ---------------------

Nanda Kishore. M

Senior PHP Developer

http://php-desk.blogspot.com

Mobile: + 91 98499 71144


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Niels Braczek  
View profile  
 More options Jul 28 2012, 6:46 am
From: Niels Braczek <nbrac...@bsds.de>
Date: Sat, 28 Jul 2012 12:46:08 +0200
Local: Sat, Jul 28 2012 6:46 am
Subject: Re: [jgen] How the Joomla MVC will call the functions in a custom component...?
Am 28.07.2012 05:59, schrieb fornandakishore:

> 1. When I create a menu link the menu appears ex: www.site.com/
> index.php?option=com_mycom&view=default&layout=mylayout

> => I need to know how this will execute. It seems to me first it is calling
> view.html.php => display() function, here when it will go to controller
> task functions.

http://docs.joomla.org/Component_Program_Flow is for Joomla 1.5 but the
big picture didn't change.

Regards,
Niels

--
| http://barcamp-wk.de   ·   2. Barcamp Westküste    Frühjahr 2013 |
| http://www.bsds.de   ·   BSDS Braczek Software- und DatenSysteme |
| Webdesign · Webhosting · e-Commerce · Joomla! Content Management |
 ------------------------------------------------------------------


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Weavers  
View profile  
 More options Jul 29 2012, 5:12 am
From: Nick Weavers <nickweav...@yahoo.co.uk>
Date: Sun, 29 Jul 2012 02:12:15 -0700 (PDT)
Local: Sun, Jul 29 2012 5:12 am
Subject: Re: How the Joomla MVC will call the functions in a custom component...?

I posted a similar question some time ago:  
https://groups.google.com/forum/?fromgroups#!search/nick$20weavers$20...

If you find a way to do it I would be interested to know.

Nick


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Swapnil Shah  
View profile  
 More options Jul 29 2012, 10:00 am
From: Swapnil Shah <swapnilsha...@gmail.com>
Date: Sun, 29 Jul 2012 10:00:19 -0400
Local: Sun, Jul 29 2012 10:00 am
Subject: Re: [jgen] How the Joomla MVC will call the functions in a custom component...?

I think there is distinction that need to be made. Nick hopefully this will answer you question too.

When a user clicks on a menu item what are they doing? They are performing an action. By default the user is performing the display action. They don't want todo anything else yet but see the page.

If you want to display different forms, why not have a drops down with a list of forms you want to display. Then in your model you can determine which form the user wants to see and you display that form. You can have different views for each of the forms if you choose.

The controller looks for the task variable, since that is what you are retrieving from get/post and passing it to execute. If you use a dot separate task, for example: subcontroller.task, joomla will look for a sub controller and  a function with the name of "task".

You can look at the login module. It performs two different actions. user.login and user.logout. Under the com_users/controller folder there is a file called user with a sub controller named UserControllerUser with functions called login and logout.

You can have a menu item perform an action, you just need to have a request variable or variables that can be selected. You can specify that in An XML file in the tmpl folder inside the views/<viewname> folder.

Hope that helps!
Regards,

Neil
Sent from my iPhone

On Jul 27, 2012, at 11:59 PM, fornandakishore <fornandakish...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
srgg01  
View profile  
 More options Jul 29 2012, 2:02 pm
From: srgg01 <srg...@gmail.com>
Date: Sun, 29 Jul 2012 11:02:10 -0700 (PDT)
Local: Sun, Jul 29 2012 2:02 pm
Subject: Re: How the Joomla MVC will call the functions in a custom component...?

Yes, you'll get the task executed by controller directly only if you pass
URL parameter 'task'. It will trigger an appropriate task in a controller.
You see controllers mostly are for such a purpose.
However there are some tricks to do that in other way. You may catch any
URL parameter in view.html.php (your default view, in display()).
After that you may do all you need - get any model, call any method etc.

for example:

   if (JRequest::getVar('myurl')) {
      $this->getModel('modelName')->myTaskMethod();
  }
(usualy, tasks implement in models).
But question is - what you  want to implement the task for without passing
its URL parameter?
суббота, 28 июля 2012 г., 7:59:20 UTC+4 пользователь Nandu написал:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fornandakishore  
View profile  
 More options Jul 29 2012, 3:20 pm
From: fornandakishore <fornandakish...@gmail.com>
Date: Mon, 30 Jul 2012 00:50:26 +0530
Local: Sun, Jul 29 2012 3:20 pm
Subject: Re: [jgen] Re: How the Joomla MVC will call the functions in a custom component...?

Thanks to all,

*@srgg01*

suppose if you have many layouts, some layout needs to fetch some data to
display the layout information.

Here my question is you have created some menu items for different layouts,
when you click on these menus by default all these will go the display()
function in the view.html.php.

So if you want to fetch data for some particular layouts (not for all the
layouts), how to call those particular functions for those layouts from the
display() function.

And also is there any possibilities of calling a controller task from
view.html.php

Thanks & Regards

Nanda Kishore. M
Senior PHP Developer

http://php-desk.blogspot.com

Mobile: + 91 98499 71144


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
srgg01  
View profile  
 More options Jul 29 2012, 3:52 pm
From: srgg01 <srg...@gmail.com>
Date: Sun, 29 Jul 2012 12:52:09 -0700 (PDT)
Local: Sun, Jul 29 2012 3:52 pm
Subject: Re: How the Joomla MVC will call the functions in a custom component...?

>suppose if you have many layouts, some layout needs to fetch some data to

display the layout information.
Here my question is you have created some menu items for different layouts,
when you click on these menus by default all these will go the display()
function in the view.html.php.

Sorry, I'm not quite uderstand - when you click on these menus by default
all these will go the display() function in the view.html.php - do you mean
that you WANT them to do that or you suppose that there it happens now?

суббота, 28 июля 2012 г., 7:59:20 UTC+4 пользователь Nandu написал:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fornandakishore  
View profile  
 More options Jul 30 2012, 7:16 am
From: fornandakishore <fornandakish...@gmail.com>
Date: Mon, 30 Jul 2012 16:46:59 +0530
Local: Mon, Jul 30 2012 7:16 am
Subject: Re: [jgen] Re: How the Joomla MVC will call the functions in a custom component...?

@srgg01,

I will try to explain bit clear here... when you create a menu items these
links looks like the below...

index.php?option=com_mycom&view=myview&layout=testlayout1
index.php?option=com_mycom&view=myview&layout=testlayout2
index.php?option=com_mycom&view=myview&layout=testlayout3

In all these above cases by default when you click on these menu links it
will take you to the display() function in the view.html.php

For suppose if you want to display some data for testlayout2 and
testlayout3, so how can we do that only for those two layouts and not for
all layouts.

Sorry for my bad english, I hope you can understand now.

Thanks & Regards

Nanda Kishore. M
Senior PHP Developer

http://php-desk.blogspot.com

Mobile: + 91 98499 71144


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Niels Braczek  
View profile  
 More options Jul 30 2012, 7:16 am
From: Niels Braczek <nbrac...@bsds.de>
Date: Mon, 30 Jul 2012 13:16:51 +0200
Local: Mon, Jul 30 2012 7:16 am
Subject: Re: [jgen] Re: How the Joomla MVC will call the functions in a custom component...?
Am 30.07.2012 13:16, schrieb fornandakishore:

> index.php?option=com_mycom&view=myview&layout=testlayout1
> index.php?option=com_mycom&view=myview&layout=testlayout2
> index.php?option=com_mycom&view=myview&layout=testlayout3

> In all these above cases by default when you click on these menu links it
> will take you to the display() function in the view.html.php

> For suppose if you want to display some data for testlayout2 and
> testlayout3, so how can we do that only for those two layouts and not for
> all layouts.

In the controller (MycomController or MycomControllerMyview) display()
method, add all relevant models to the view. The layout files can then
draw all the data they want and need.

Regards,
Niels

--
| http://barcamp-wk.de   ·   2. Barcamp Westküste    Frühjahr 2013 |
| http://www.bsds.de   ·   BSDS Braczek Software- und DatenSysteme |
| Webdesign · Webhosting · e-Commerce · Joomla! Content Management |
 ------------------------------------------------------------------


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fornandakishore  
View profile  
 More options Jul 30 2012, 11:48 am
From: fornandakishore <fornandakish...@gmail.com>
Date: Mon, 30 Jul 2012 21:18:37 +0530
Local: Mon, Jul 30 2012 11:48 am
Subject: Re: [jgen] Re: How the Joomla MVC will call the functions in a custom component...?

*@Niels,*

here my question how can we do that, Through display() function in
view.html.php like the below or any other way.

I mean :  my view.html.php display() function

public function display() {

     $values = JRequest::get('request');
     if (!empty ($values['layout']) && $values['layout'] == testlayout2)) {
          // here my model calls
     }

}

Is this is the only way or any other ways ?

Thanks & Regards

Nanda Kishore. M
Senior PHP Developer

http://php-desk.blogspot.com

Mobile: + 91 98499 71144


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Niels Braczek  
View profile  
 More options Jul 30 2012, 11:15 am
From: Niels Braczek <nbrac...@bsds.de>
Date: Mon, 30 Jul 2012 17:15:58 +0200
Local: Mon, Jul 30 2012 11:15 am
Subject: Re: [jgen] Re: How the Joomla MVC will call the functions in a custom component...?
Am 30.07.2012 17:48, schrieb fornandakishore:

> here my question how can we do that, Through display() function in
> view.html.php like the below or any other way.

> public function display() {

>      $values = JRequest::get('request');
>      if (!empty ($values['layout']) && $values['layout'] == testlayout2)) {
>           // here my model calls
>      }
> }

It doesn't harm to provide the models to all layouts.

In the controller:
public function display()
{
    ...
    $view = $this->getView();
    $view->setModel($mainModel, true);
    $view->setModel($otherModel);
    ...

}

In tmpl/testlayout2.php, you can retrieve the models by name to get and
process additional data.

Regards,
Niels

--
| http://barcamp-wk.de   ·   2. Barcamp Westküste    Frühjahr 2013 |
| http://www.bsds.de   ·   BSDS Braczek Software- und DatenSysteme |
| Webdesign · Webhosting · e-Commerce · Joomla! Content Management |
 ------------------------------------------------------------------


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
srgg01  
View profile  
 More options Jul 30 2012, 2:09 pm
From: srgg01 <srg...@gmail.com>
Date: Mon, 30 Jul 2012 11:09:46 -0700 (PDT)
Local: Mon, Jul 30 2012 2:09 pm
Subject: Re: How the Joomla MVC will call the functions in a custom component...?

It seems to me my English is worser than yours one :)
Look, there is one standard way to manage all content. Beyond it using MVC
just doesn't make sense.
When you load ANY page you ALWAYS first of all get a Component_name.phpfile which creates
an instance of Controller.

You can find out there (I guess at any component_name.php file) such a code:

// Include dependancies
jimport('joomla.application.component.controller');
$controller    = JController::getInstance('Component_name');

Got it?

So if you think you escape a controller and get view.html.php passing it
it's not true. Maybe it looks like controller does nothing but it doesn't
mean that there it is not.
Do you guess that it means? It give you a possibility to manage all your
content and scripts as you want.
If you dont't know how to load needed layout here is some ideas:
You can parse URL and then assign an actual layout to the view. Like this:

      function display() <#_msocom_1>

      {

         // Set the view and the model

         $view   = JRequest::getVar( 'view' <#_msocom_2> , 'current_view'<#_msocom_3>
  );

         $layout = JRequest::getVar( 'layout' <#_msocom_4>, 'default'<#_msocom_5>
  );

         $view  =& $this->getView( $view, 'html' ); <#_msocom_6>

         $model =& $this->getModel<http://docs.joomla.org/API15:JView/getModel#Source_Body>(
'modelName' ); <#_msocom_7>

         $view->setModel<http://docs.joomla.org/API15:JView/setModel#Source_Body>(
$model, *true* ); <#_msocom_8>

         $view->setLayout<http://docs.joomla.org/API15:JView/setLayout#Source_Body>(
$layout <#_msocom_9>  );

         // Display the content

         $view->display(); <#_msocom_10>

       }
After that it shold load that layout that was assigned.
Try it pls and tell us if you got success!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
srgg01  
View profile  
 More options Jul 30 2012, 2:29 pm
From: srgg01 <srg...@gmail.com>
Date: Mon, 30 Jul 2012 11:29:26 -0700 (PDT)
Local: Mon, Jul 30 2012 2:29 pm
Subject: Re: How the Joomla MVC will call the functions in a custom component...?

Of course, that code implements in a controller. And you may not to call a
Model if you don't need that - there was just a standart approach to manage
things.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »