Version 12, last updated by Johan Janssens at 24 Feb 23:35 UTC

1 KModel

Nooku Framework now implements a transparent and auto-persistent model state system or in layman's terms : 'You don't need to write any JApplication::getUserStateFromRequest or setUserStateFromRequest any more in your models'. Nooku Framework remembers your views state. And all of this is done out of the box. Neat huh !

With the change we also move closer to fully RESTable URL's. From now on KControllerBread expects the state information to be part of the GET request and not the POST request, or said otherwise the information needs to be part of the URI itself. This in turn leads to cleaner and more humanly readable URL's and in the end will lead to almost transparent REST support. Well that's the plan anyway ;-)

To taken advantage of the auto-persistent model state you will need to re-work your views to use GET requests when implementing filters (like a search box). The new KTemplateHelperPaginator and KModelPaginator already do some of the heavy lifting for you but if you are defining your own filters or implementing a search field in your backend list views you will need to move from using POST to GET requests.

For an example please checkout the com_habour example and especially the boats view. It show you how to implement a search filter for your view and demonstrates the transparent auto-persistency in action.

To test it. Install the harbour component, typ something in the search field, go to another page and then come back. The view will have remember your previous settings ! All transparent, all without writing a single line of code. Code can be a little bit like magic ;-)

1.1 A peek under the hood

  • The models implement the state as a KModelState object. This is a special model that is designed to keep model state. KModelState is implemented in KModelAbstract as a sub-model. You can get the state model by doing KModelAbstract::getState() and then you can use the functions as defined in KModelState.

  • Setting things up is quite simple. All you need to do is declare the state properties and their types in your own models to make Nooku Framework aware of them. That's it ! This is done through the KModelState::insert() function. Example in the KModelTable constructor you will find :

// Set the state

$this->_state
    ->insert('limit'    , 'int', 0)
->insert('offset'   , 'int', 0)
->insert('order'    , 'cmd')
->insert('direction', 'word', 'asc')
->insert('search'   , 'string');

The KModelState::insert() function defines three things: name, filter, default value and the fourth parameter is a boolean to indicate of the state is unique. The filter is important to allow auto-filtering when data is being pushed into the model using KModelState::setData() function.

You can compare this with the way KDatabaseTableAbstract::filter() filters data based on the schema information. For the models we need to explicitly tell it about the state filter it needs to use.

2. KToolbar

Default BREAD style toolbars are now created by KToolbarDefault. Based on the plural or singular form of the toolbar name either new, edit, delete buttons or save, apply, cancel buttons are added to the toolbar.

The default toolbars are only created when ComDefaultViewHtml is used. In other cases the default toolbar needs to be manually created through KFactory.

3. KController

ComDefaultControllerView sets the default layout to 'form' instead of 'default' for browse and read actions. If you are using ComDefaultControllerView then your layouts will need to be renamed to 'form' or you will need to force the layout to 'default' either by using KView::setLayout() or by specifying the layout in the URL.

4. Paginator

  • Pagination has been renamed to Paginator.

  • The KModelPaginator model now extends KModelState and thus is a specialized version of the state model. You can interact with a paginator object in the same way as you interact with the state model.

  • The KTemplateHelperPaginator will generate GET request and not POST request like the Joomla paginator does. (see also 1)

5 Other

  • KMixinCommand now also accepts an array of methods when registering or unregistering functions this is handy when you are registering a certain filter to multiple methods. Spares you some extra typing and keeps the code lean and mean.

  • KView::createRoute has been made a bit smarter. If the route is empty then a default route will be procuded. This allows you to do things like @route() in your templates and he will create the current route for you. Especially handy in forms in action attributes.

  • Added KHelperArray::merge() function to allow for recursive and distinct merging of two arrays. Implemented KHelperArray::merge() to fix bug when handling nested arrays in KRequest::set()