JInput in ModelLegacy

92 views
Skip to first unread message

over

unread,
Nov 13, 2012, 6:58:30 AM11/13/12
to joomla-...@googlegroups.com
Hi,

I'm replacing JRequest with JInput and found the following difference in the handling.

Is there a reason for adding $this->input in ControllerLegacy but not in ModelLegacy?

From the controller:
    /**
     * Hold a JInput object for easier access to the input variables.
     *
     * @var    JInput
     * @since  12.2
     */
    protected $input;

......

    public function __construct($config = array())
......
        $this->input = JFactory::getApplication()->input;

.....

 for easier access I added a __construct partly only including this to my models .


Ove

Dmitry Rekun

unread,
Nov 13, 2012, 11:32:52 AM11/13/12
to joomla-...@googlegroups.com
Hi.

Why we need JInput in the models? It is the responsability of the controllers to manage the request and setup models and views based on that request.

Dmitry.

Ove

unread,
Nov 13, 2012, 12:48:22 PM11/13/12
to joomla-...@googlegroups.com, Dmitry Rekun
Simple example from frontend article model. The request includes much
more after submitting a complex form with data.

/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState()
{
$app = JFactory::getApplication('site');

// Load state from the request.
$pk = $app->input->getInt('id');
$this->setState('article.id', $pk);

$offset = $app->input->getUInt('limitstart');
$this->setState('list.offset', $offset);

public function hit($pk = 0)
{
$input = JFactory::getApplication()->input;
$hitcount = $input->getInt('hitcount', 1);

Michael Babker

unread,
Nov 13, 2012, 12:53:27 PM11/13/12
to joomla-...@googlegroups.com
In the new MVC, controllers have to be instantiated with a JInput object.  So JControllerLegacy was given that input object to add a little compatibility between the two.  The models don't require it, but there's nothing to say you can't set it up for your own models.

-Michael

Please pardon any errors, this message was sent from my iPhone.
--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-cms/-/iY_3m_q0TuEJ.
To post to this group, send an email to joomla-...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-cm...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-cms?hl=en-GB.

Ove

unread,
Nov 13, 2012, 1:43:25 PM11/13/12
to joomla-...@googlegroups.com, Michael Babker
Thanks Michael,
In the new MVC, controllers have to be instantiated with a JInput object.  So JControllerLegacy was given that input object to add a little compatibility between the two.  The models don't require it, but there's nothing to say you can't set it up for your own models.

I thinks I'll use the same convention in the models as in the controllers and so beeing able to easily find all former "JRequests".

Ready for any comming depreciation ;-) 

Maybe in those days I have to add that the line above is a joke.

Best,

Ove


piotr_cz

unread,
Nov 14, 2012, 5:22:41 AM11/14/12
to Joomla! CMS Development

I have a theoretical question about Joomla MVC:

In core components there's populateState method which most of the time
uses JInput/ JRequest to fetch some model data from request.

Isn't it a responsibility of controller to setup the model after
creating it?


On Nov 13, 6:53 pm, Michael Babker <michael.bab...@gmail.com> wrote:
> In the new MVC, controllers have to be instantiated with a JInput object.  So JControllerLegacy was given that input object to add a little compatibility between the two.  The models don't require it, but there's nothing to say you can't set it up for your own models.
>
> -Michael
>
> Please pardon any errors, this message was sent from my iPhone.
>
> On Nov 13, 2012, at 5:58 AM, over <tobby.eriks...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I'm replacing JRequest with JInput and found the following difference in the handling.
>
> > Is there a reason for adding $this->input in ControllerLegacy but not in ModelLegacy?
>
> > From the controller:
> >     /**
> >      * Hold a JInput object for easier access to the input variables.
> >      *
> >      * @var    JInput
> >      * @since  12.2
> >      */
> >     protected $input;
>
> > ......
>
> >     public function __construct($config = array())
> > ......
> >         $this->input = JFactory::getApplication()->input;
>
> > .....
>
> >>  for easier access I added a __construct partly only including this to my models .
>
> > Ove
>
> > --
> > You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
> > To view this discussion on the web, visithttps://groups.google.com/d/msg/joomla-dev-cms/-/iY_3m_q0TuEJ.

Adam Stephen Docherty

unread,
Nov 14, 2012, 10:45:45 AM11/14/12
to joomla-...@googlegroups.com
"Isn't it a responsibility of controller to setup the model after 
creating it?"

I have often wondered about this as well when seeing JRequest calls in models to populate state. It maybe due to the way Joomla auto instantiates model and view classes, with there not normally being a manual instantiation of the model I guess they put the Request / user  state stuff in the model. It has never seemed right to me that this is done in the model when the controller seems a more apt place to set model states - or even the view... hmm but not the model it's self, I think the model should not set it's own state internally...

Dmitry Rekun

unread,
Nov 14, 2012, 11:42:42 AM11/14/12
to joomla-...@googlegroups.com
That's a good question. I am also think that controllers should do that work. Models should be aware of request as much as possible, imho.

Dmitry.

piotr_cz

unread,
Nov 14, 2012, 2:11:14 PM11/14/12
to Joomla! CMS Development
It occurred to me when studying MVC patterns and setting Joomla model
state by non-user inputs like REST data and other models.

I guess models should not care about the input (JRequest/ JInput), but
data

Dmitry Rekun

unread,
Nov 16, 2012, 12:59:57 AM11/16/12
to joomla-...@googlegroups.com
Yeap, that's the point. Take the model out, put it in another enviorment and it should work.

piotr_cz

unread,
Nov 16, 2012, 4:37:06 AM11/16/12
to Joomla! CMS Development
Challenge for new MVC :)
Reply all
Reply to author
Forward
0 new messages