Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Context state overrides 30 Oct 2016 11:14 #14666

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
I ask this question once per year, as every year it gives me great grief

I have two views, same table, each will have different limits and default ordering.. here is what I have so far
public function populateState($ordering = null, $direction = null)
    {
        // Initialise variables.
        $app = JFactory::getApplication();
        $session = JFactory::getSession();
        $acl = MyComponentHelper::getActions();

        parent::populateState('a.film_title', 'asc');
        $this->setState('list.limit', 15); 

        if($this->context == "films.latestfilms")
        {
            parent::populateState('a.creation_date', 'desc');
            $this->setState('list.limit', 10);  
        }
    }

The overall state works (film title, 15)

but the contextual one (lates films) doesnt

How can I correctly code this populate state to work

Thanks
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla

Please Log in or Create an account to join the conversation.

Context state overrides 30 Oct 2016 13:47 #14667

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
As odering was not really a necessary feature for user selection in my app, I just wrote the ordering into the SQL
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla

Please Log in or Create an account to join the conversation.

Context state overrides 30 Oct 2016 19:42 #14668

Does the if statement: if($this->context == "films.latestfilms") work?

I always fork the model function prepareQuery for this. Then use $this->addOrder to it.

Please Log in or Create an account to join the conversation.

Context state overrides 31 Oct 2016 11:16 #14670

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 279
  • Thank you received: 36
If you have 2 views from a Table you should find the 2 'case' treatment in the model.
case 'view 1':
....
break;

case 'films.latestfilms':
....
//LIMIT
$this->setState('list.limit', 10);
//ORDER
$query->order('a.creation_date desc');	

break;

I think it's the right place to do that and It works fine ...

Please Log in or Create an account to join the conversation.

Context state overrides 01 Nov 2016 11:04 #14672

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Missing the component alias : com_xxxxx

There are 2 ways to get the model context :

1.
$this->context; (from the model itself) OR $model->get('context');
It contains the full namespaced context : com_xxxxxx.films.latestfilms

2.
$model->getState('context')
It only contains the relative context : films.latestfilms

- If you call getState() from the populateSate() function, you will end with a endless recursive loop. So you need to use the first method.
if ($this->context == 'com_xxxxxx.films.latestfilms')
{
	$this->setState('list.limit', 10);
}
Coding is now a piece of cake
The following user(s) said Thank You: organicwebs

Please Log in or Create an account to join the conversation.

Last edit: by admin.
  • Page:
  • 1
Time to create page: 0.062 seconds

WOW.. WOW... WOW... This is awesome... in less than 3 hours of work I have my application done... this is simply the best tool I ever tried to generate Joomla Components... Thank you very much for this tool and your answer.. it helped me a lot... My friends here in Brazil are going nuts with this...
Griiettner (Forum)

Get Started