Version 14, last updated by fonny at June 26, 2011 17:52 UTC
Tips and tricks
1. Autosuggest in Eclipse
To fully expose the Nooku API while working in Eclipse PDT, there's a handy trick. First make sure that your project is a PHP project in Eclipse PDT:
Right-click your project -> Configure -> Add PHP support
Then put Nooku Framework in your include path: Right-click a project -> Properties -> PHP Include path -> Libraries -> Add external source folder -> /path/to/libraries/koowa
You might need to close and reopen your project. You now have API hints while coding, auto suggest, and you can use F4 from inside your code to see the Type Hierarchy.
Note : This only works with Eclipse PDT 2.2 and higher.
2. Build API Documentation
Follow these steps to build your own copy of the API documentation.
- Install PhpDocumentor http://pear.php.net/package/PhpDocumentor/download
-
Run this command:
phpdoc -s on -ti KoowaDocumentation -ue on -t /TARGETPATH/ -d /PATH/TO/libraries/koowa -dn Koowa -o HTML:frames:DOM/earthli Open /TARGETPATH/index.html
- Instead of the command, you can use the bash script in /releases/0.6/scripts/docs/generate.sh
Note: the documentation is also available at http://api.nooku.org
3. Checking out from SVN
The Nooku Framework repository is getting quite big, and will only get bigger in the future. It's best to never check out the entire repository. Better only check out the folder you explicitly need, eg /trunk/, /tags/0.6.5/, /branches/100-view/ etc
Doing this will leave more bandwidth available for other users, and you won't have to wait all the time to update branches you don't need anyway.
4. Using modals for your views
Squeezebox (the modal box included with Joomla) uses POST requests by default while Nooku rightfully needs GET for read and browse actions.
So if you are getting an "Invalid token or session time-out" error, you should modify your link like this:
<a href="<?= @route('yourroute'); ?>" class="modal" rel="{'ajaxOptions': {'method': 'get'}}">
Please note that you should use lowercase "get" in your HTML code as Mootools does not accept uppercase words for method.
Add &tmpl=component to your URL to only load the component output and not the whole template.
To modify the size of the modal window change :
rel="{'ajaxOptions': {'method': 'get'}}"
to
rel="{size : {x: 100, y: 100}, 'ajaxOptions': {'method': 'get'}}"
For a list of all settings see the code in media/lib_koowa/js/modal.js
5. Invalid token or session time-out - POST requests.
When developing your NOOKU components there may be situations where you need to use a POST request, for example - triggering an action.
To facilitate fully RESTful URLS, you cannot trigger an action using a GET request.
Using a POST request leaves you open to the possibility of getting an Invalid token or session timeout error as the dispatcher automatically performs a token check on every non GET request in its constructor:
if(KRequest::method() != 'GET')
{
$this->registerCallback('before.dispatch', array($this, 'authorize'));
$this->registerCallback('after.dispatch' , array($this, 'forward'));
}
/*---------------------------------------------------------------------------------*/
public function _actionAuthorize(KCommandContext $context)
{
if( KRequest::token() !== JUtility::getToken())
{
throw new KDispatcherException('Invalid token or session time-out.', KHttp::UNAUTHORIZED);
return false;
}
} As you can see from above KRequest::token() is checked against JUtility::getToken() and this is where you will get your invalid token error.
If you take a look at the KRequest::token() function you will see that it is searching for a variable in the request array with a key of ''_token". In this situation, unless you explicitly provide "_token" as a POST variable with the same value as JUtility::getToken(), you will get the error.
Example:
<input type="hidden" name="_token" value="<?php echo JUtility::getToken(); ?>"Tokens are used to prevent Cross-Site Request Forgery (CSRF)
6. Usage of PHP short tags
Sometimes you may notice, only on some server configurations where PHP short tags are not enabled, that code is not translated to PHP. For example when customizing the toolbar buttons.
That's why if PHP short tags are OFF on the server, Nooku converts <? to <?php, not in all your PHP files, but only in the views, so the only place where you're safe to use them is there.
Anywhere else the standard syntax <?php should be used to open a PHP block, to be sure it won't fail.