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 ?
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()
> 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.
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:
> => 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
> => 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 ?
> 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()
> -- > You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
> To post to this group, send an email to joomla-dev-general@googlegroups.com.
> To unsubscribe from this group, send email to joomla-dev-general+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
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 написал:
> 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 ?
> 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()
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
On Sun, Jul 29, 2012 at 11:32 PM, srgg01 <srg...@gmail.com> wrote:
> 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 написал:
>> 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.
>> => 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
>> => 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 ?
> To post to this group, send an email to
> joomla-dev-general@googlegroups.com.
> To unsubscribe from this group, send email to
> joomla-dev-general+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.
>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 написал:
> 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 ?
> 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()
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.
On Mon, Jul 30, 2012 at 1:22 AM, srgg01 <srg...@gmail.com> wrote:
> >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 написал:
>> 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.
>> => 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
>> => 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 ?
> To post to this group, send an email to
> joomla-dev-general@googlegroups.com.
> To unsubscribe from this group, send email to
> joomla-dev-general+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.
> 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.
> > 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.
> --
> You received this message because you are subscribed to the Google Groups
> "Joomla! General Development" group.
> To post to this group, send an email to
> joomla-dev-general@googlegroups.com.
> To unsubscribe from this group, send email to
> joomla-dev-general+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.
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:
On Saturday, 28 July 2012 07:59:20 UTC+4, Nandu wrote:
> 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 ?
> 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()
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.
On Saturday, 28 July 2012 07:59:20 UTC+4, Nandu wrote:
> 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 ?
> 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()