Documentation on Find Resources

Only by trial and error did I find out that the correct php command to find the filesystem path of the /user/pages directory is:

$this->grav['locator']->findResource('page://');

Some failed tries were:

$this->grav['locator']->findResources('pages://');
$this->grav['locator']->findResource('pages');

Fairly frequently I dive into the Grav API documentation but for some reason, which for a large part is my limited dev knowledge, I can’t make the connection with the rest of the documentation. I hope I have been looking on the wrong places. Any hints are greatly appreciated! Thanks.

Well the official API doc for this is here: RocketTheme\Toolbox\ResourceLocator\ResourceLocatorInterface.

Everything I learned about this I learned by looking at other plugins and trial and error. This is only mentioned in the main docs in one, nonintuitive place. The team is pretty open to pull requests against the docs, if you have some ideas for improvement.

It’s nice to know that I’m not the only one who is struggling. Regarding the docs, these are pretty good. What I need are more examples like you are doing in the Cookbook. Great work.

The Grav Debug bar is very helpful as I often do things like:

// debug info:
$this->grav['debugger']->addMessage('rootUrl() = '.$this->grav['uri']->rootUrl() );
$this->grav['debugger']->addMessage('basename() = '.$this->grav['uri']->basename() );
$this->grav['debugger']->addMessage('base() = '.$this->grav['uri']->base() );
$this->grav['debugger']->addMessage('host() = '.$this->grav['uri']->host() );
$this->grav['debugger']->addMessage('path() = '.$this->grav['uri']->path() );
$pages = $this->grav['pages'];
$page = $this->grav['page'];
$this->grav['debugger']->addMessage('filePath() = '.$page->filePath() );
$this->grav['debugger']->addMessage('filePathClean() = '.$page->filePathClean() );
$this->grav['debugger']->addMessage('relativePagePath() = '.$page->relativePagePath() );

which then shows this in the Debug bar:

rootUrl() = /grav
basename () = editable
base() = http://localhost
host() = localhost
path() = /editable
filePath() = /Users/rwgc/devroot/repos/grav/user/pages/02.editable/default.en.md
filePathClean() = user/pages/02.editable/default.en.md
relativePagePath() = user/pages/02.editable

Thanks!

I dump() liberally :slight_smile:

Yes, dump() is handy as well. Right now I do a lot of testing with AJAX requests and so dump() and the Debug bar are of little use.
So, only if you promise not to laugh, I’ll let you (all) in on my debug method:

#start buffering (all activity to the buffer)
ob_start() ;
# dumps to buffer
var_dump('ROUTE: '.$target_dir) ;
# dump buffered $classvar to $outStringVar
$outStringVar = ob_get_contents() ;
# open your file with append, read, write perms
# (be sure to check your file perms)
$fp=fopen('mylog.html','a+');
# write output to file & close it
fwrite($fp, $outStringVar );
fclose($fp);
# clean the buffer & stop buffering output
ob_end_clean() ;

By examining the file my log.html I can test things an d learn a lot while at the same time I know there must be better ways than this… :slight_smile:

No judgement here! :slight_smile: Grav has a built-in file logger, too.

Somehow I missed that part of the docs. Thanks VERY much for pointing me to it !