1. Go to this page and download the library: Download xire28/redbean-traversing library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xire28 / redbean-traversing example snippets
class Model_Country extends RedBean_SimpleModel
{
use RedbeanTraversing\ModelTraversing;
public function people(){
return $this->multi()->ownState->ownPerson;
}
}
$usa = R::load('country', 1);
echo '<ul>';
foreach($usa->people() as $person){
echo "<li>{$person->fullName}</li>";
}
echo '</ul>';
class BaseModel extends RedBean_SimpleModel
{
use RedbeanTraversing\ModelTraversing;
}
class Model_Country extends BaseModel
{
public function adultPersons(){
return $this->multi()->ownState->isAdult()->ownPerson;
}
}
class Model_State extends BaseModel
{
use PersonScope;
}
trait PersonScope {
public function isAdult(){
return $this->personOlderThan(17);
}
public function personOlderThan($age){
return $this->where('TIMESTAMPDIFF(YEAR, born_at, CURDATE()) > ?', $age);
}
}
$usa = R::load('country', 1);
echo '<ul>';
foreach($usa->adultPersons() as $person){
echo "<li>{$person->fullName}</li>";
}
echo '</ul>';
class BaseModel extends RedBean_SimpleModel
{
use RedbeanTraversing\ModelTraversing;
}
class Model_Country extends BaseModel {}
class Model_State extends BaseModel {}
$usa = R::load('country', 1);
echo '<ul>';
foreach($usa->multi()->group(function($q){ return $q->where('name LIKE "Ar%"')->_or()->where('name = ?', 'Alabama'); })->ownState->ownPerson as $person){
echo "<li>{$person->fullName}</li>";
}
echo '</ul>';
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.