US federal campgrounds for Yii 2: filter 3,948 Recreation.gov campgrounds by state, agency, amenities and RV length, find the nearest ones to a point, show them in a GridView, export GeoJSON for a map, or search them from the console. No API key, no network request and no database: the data (the public RIDB export of 2026-11-16) ships with the extension.
Requirements ¶
- Yii 2.0.45 or later, PHP 8.0 or later
Installation ¶
The package is installed from its GitHub repository with Composer:
"repositories": [
{ "type": "vcs", "url": "https://github.com/campkitchenus-maker/yii2-ridb-campgrounds" }
]
composer require campkitchenus/yii2-ridb-campgrounds
Or download the release zip and autoload src/ under the campkitchenus\campgrounds namespace.
Usage ¶
'components' => [
'campgrounds' => ['class' => \campkitchenus\campgrounds\Campgrounds::class],
],
$cg = Yii::$app->campgrounds;
$rows = $cg->find(['states' => ['CA', 'OR'], 'amenities' => ['rv', 'electric'], 'minRigFt' => 35]);
$near = $cg->nearest(37.7459, -119.5332, 5, ['reservable' => true]); // each row gets distanceMi
echo \yii\grid\GridView::widget([
'dataProvider' => $cg->dataProvider(['states' => 'UT', 'amenities' => ['tent']]),
'columns' => ['name', 'agency', 'sites', 'maxRigFt'],
]);
Filters: states, agencies, reservable, minSites, amenities (tent, rv, electric, water, firePit, picnicTable, pets, accessible), minRigFt, includeUnknownRig, bbox and q (name search). Unknown filters or amenities throw an InvalidArgumentException instead of returning nothing.
Console (controllerMap entry campgrounds):
yii campgrounds/search --state=CA --amenities=rv,electric --min-rig-ft=40 --limit=5
yii campgrounds/search --near=44.428,-110.588 --limit=3 --format=csv
Tests ¶
PHPUnit: 12 tests, 151 assertions, run on Yii 2.0.55 with PHP 8.5, plus the console commands and a GridView page in a Yii app.
Credits ¶
Data Source: Recreation.gov (show Campgrounds::ATTRIBUTION in your UI); not affiliated with or endorsed by Recreation.gov. The same data drives the campground map on campkitchen.us. Made by Camp Kitchen US with help from an AI assistant, then tested as described above. MIT License.
User Contributed Notes
Leave a comment
If you have any questions, please ask in the forum instead.
Join the conversation to share a note.