本文整理汇总了PHP中Silex\Application::getRepository方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getRepository方法的具体用法?PHP Application::getRepository怎么用?PHP Application::getRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\Application
的用法示例。
在下文中一共展示了Application::getRepository方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: blogIndexAction
public function blogIndexAction(Application $app, Request $request)
{
$repo = $app->getRepository('blog');
$entities = $repo->findAll();
print_r($entities);
exit;
$data = array('name' => 'blog', 'entities' => $entities);
return new Response($app['twig']->render('@Templates/blog/index.html.twig', $data));
}
示例2: eventPostSave
/**
* Post-save testing event.
*
* @param StorageEvent $event
*/
public function eventPostSave(StorageEvent $event)
{
$contentType = $event->getContentType();
if ($contentType === 'pages') {
$repo = $this->entityManager->getRepository($contentType);
/** @var Content $record */
$record = $event->getContent();
$values = $record->serialize();
if ($event->isCreate()) {
// Add a unique paragraph to the end of the body
$record->setBody($values['body'] . '<p>Snuck in to body during POST_SAVE on create: ' . date('Y-m-d H:i:s') . '</p>');
} else {
// Add a unique paragraph to the end of the body
$record->setBody($values['body'] . '<p>Added to body during POST_SAVE on save: ' . date('Y-m-d H:i:s') . '</p>');
}
// Save the changes to the database
$repo->save($record, true);
}
}
示例3: delete
public function delete(Application $app, Request $request, $id)
{
$repo = $app->getRepository($this->getModelName());
try {
$repo->remove($repo->find($id));
} catch (PDOException $e) {
$app->addFlash('error', $e->getMessage());
}
// @todo Check errors
return $app->redirect($app['url_generator']->generate(sprintf('%s_index', $this->getModelName())));
}