Created
February 10, 2021 10:52
-
-
Save sorbing/beeff84dc17446fc191f5d729aa7a4da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ~ ~ ~ ~ ~ ~ ~ DB Connect | |
require __DIR__ . '/vendor/gabordemooij/redbean/RedBean/redbean.inc.php'; | |
R::setup('mysql:host=' . $config['db_host'] . ';dbname=' . $config['db_name'], $config['db_user'], $config['db_pass']); | |
R::debug(false); | |
R::exec('SET NAMES utf8'); | |
R::exec('SET CHARACTER SET utf8'); | |
// Автозагрузка моделей: http://bit.ly/13sORIP | |
require_once __DIR__ . "/Models/Model_User.php"; | |
require_once __DIR__ . "/Models/Model_Event.php"; | |
require_once __DIR__ . "/Models/Model_Invite.php"; | |
require_once __DIR__ . "/Models/Model_Wish.php"; | |
// - - - - - - - - - - - - - - - - - - - - - - - - // | |
class Model_User extends RedBean_SimpleModel | |
{ | |
public function getHailName() | |
{ | |
return $this->fullname ? $this->fullname : $this->username; | |
} | |
} | |
// - - - - - - - - - - - - - - - - - - - - - - - - // | |
<?php | |
class Model_Wish extends RedBean_SimpleModel | |
{ | |
public function getUser() | |
{ | |
return $this->user; | |
} | |
public function isRealized() | |
{ | |
return (bool)$this->performer_id; | |
} | |
public function getPhotoOrBlank() | |
{ | |
return null; | |
} | |
} | |
// - - - - - - - - - - - - - - - - - - - - - - - - // | |
<?php | |
class Model_Invite extends RedBean_SimpleModel | |
{ | |
/** | |
* @link http://stackoverflow.com/questions/9585651/twig-how-to-natively-display-redbean-relationships-inside-template | |
*/ | |
public function getEvent() | |
{ | |
return $this->event; | |
} | |
public function getOrganizer() | |
{ | |
return $this->user; | |
} | |
} | |
// - - - - - - - - - - - - - - - - - - - - - - - - // | |
И в шаблоне дергаем : | |
<td>{{ invite.getOrganizer().username }}</td> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment