[Owncloud] Routing for Dummies and best practices

Thomas Tanghus thomas at tanghus.net
Thu Mar 21 01:01:49 UTC 2013


I could probably go the way and use the app framework, but I like to know what's happening behind
the curtains and try out simple implementations before doing that. My limited experience tells me it
pays out in the long run.
Nothing of this is tested btw, purely hypothetical.

So, in contacts app I want to get the contacts from a  specific address book. I set up a route akin to:

(say 'backend' == 'local' and 'id' == '123')

$this->create('contacts_address_book_collection', 'contacts/addressbook/{backend}/{id}/contacts')
	->get()
	->action(
		function($params){
			$app = new App();
			$addressBooks = App->getAddressBook($params['backend'], $params['id']);
		}
	);

So in my client side script I can call this by:

	var url = OC.Router.generate('contacts_address_book_collection', {backend: backend, id: id});
	$.getJSON(url, function(jsondata) {
		//
	});

And this would translate into:

	/index.php/apps/contacts/addressbook/local/123/contacts   ?

Am I right so far or have I totally misunderstood it?

So can I add more parameters to the OC.Router.generate() call and have them available in $params
or will they have to be in the URI?

And what would be most efficient: Using OC.Router.generate() or requesting the URI directly?

On a side note http://doc.owncloud.org/server/5.0/developer_manual/app/app/routes.html 
mentions OC.Router.registerLoadedCallback()
Would this be the proper way to use it:

$(document).ready(function() {
	OC.Router.registerLoadedCallback(function() {
		OC.Contacts.init();
	});
});


-- 
Best regards / Med venlig hilsen

Thomas Tanghus



More information about the Owncloud mailing list