本文整理匯總了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())));
}