actionでpropelの設定を取得

<?php
      $manager = $this->getContext()->getDatabaseManager();
      $database = $manager->getDatabase('propel');
      $phptype = $database->getParameter('phptype');
      
      print_r($database->getParameterHolder()->getAll());
Array
(
    [dsn] => mysql://USERNAME:PASSWORD@localhost/DATABASE
    [datasource] => propel
    [phptype] => mysql
    [hostspec] => localhost
    [database] => DATABASE
    [username] => USERNAME
    [password] => PASSWORD
)
  • ランダムに10件取得
<?php
      $manager = $this->getContext()->getDatabaseManager();
      $database = $manager->getDatabase('propel');
      $phptype = $database->getParameter('phptype');

      switch ($phptype) {
      case 'mysql':
        $random = 'RAND()';
        break;
      case 'sqlite':
        $random = 'random()';
        break;
      default:
        $random = null;
        break;
      }
      if (!is_null($random)) {
        $c = new Criteria();
        $c->addDescendingOrderByColumn($random);
        $c->setLimit(10);
        $random_list = HogePeer::doSelect($c);
      }