Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Documentation on Find Resources

Started by Muut Archive 10 years ago · 6 replies · 946 views
10 years ago

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:

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

Some failed tries were:

PHP
$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.

10 years ago

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:

PHP
// 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:

TXT
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!

10 years ago

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:

PHP
#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... :)

10 years ago

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

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1350 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2947 9 years ago
Archive · by Muut Archive, 9 years ago
3 1118 9 years ago