- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想在我的表单上显示数据,但我做不到。
这是我在 userbundle 下的 profile.php:
<?php
namespace project\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Profile
*
* @ORM\Table(name="project_profiles")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
*/
class Profile
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \project\UserBundle\Entity\User
*
* @ORM\OneToOne(targetEntity="\project\UserBundle\Entity\User", inversedBy="profile")
*/
private $user;
/**
* @var string
*
* @ORM\Column(name="first_name", type="string")
*/
private $firstName;
/**
* @var string
*
* @ORM\Column(name="last_name", type="string")
*/
private $lastName;
/**
* @var string
*
* @ORM\Column(name="address1", type="string")
*/
private $address1;
/**
* @var string
*
* @ORM\Column(name="address2", type="string")
*/
private $address2;
/**
* @var string
*
* @ORM\Column(name="city", type="string")
*/
private $city;
/**
* @var string
*
* @ORM\Column(name="state", type="string")
*/
private $state;
/**
* @var string
*
* @ORM\Column(name="zipcode", type="string")
*/
private $zipcode;
/**
* @var string
*
* @ORM\Column(name="country", type="string")
*/
private $country;
/**
* @var integer
*
* @ORM\Column(name="client_api_delay", type="integer")
*/
private $clientApiDelay;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set firstName
*
* @param string $firstName
* @return Profile
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
* Get firstName
*
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* Set lastName
*
* @param string $lastName
* @return Profile
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
* Get lastName
*
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* Set address1
*
* @param string $address1
* @return Profile
*/
public function setAddress1($address1)
{
$this->address1 = $address1;
return $this;
}
/**
* Get address1
*
* @return string
*/
public function getAddress1()
{
return $this->address1;
}
/**
* Set address2
*
* @param string $address2
* @return Profile
*/
public function setAddress2($address2)
{
$this->address2 = $address2;
return $this;
}
/**
* Get address2
*
* @return string
*/
public function getAddress2()
{
return $this->address2;
}
/**
* Set city
*
* @param string $city
* @return Profile
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set state
*
* @param string $state
* @return Profile
*/
public function setState($state)
{
$this->state = $state;
return $this;
}
/**
* Get state
*
* @return string
*/
public function getState()
{
return $this->state;
}
/**
* Set zipcode
*
* @param string $zipcode
* @return Profile
*/
public function setZipcode($zipcode)
{
$this->zipcode = $zipcode;
return $this;
}
/**
* Get zipcode
*
* @return string
*/
public function getZipcode()
{
return $this->zipcode;
}
/**
* Set country
*
* @param string $country
* @return Profile
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set clientApiDelay
*
* @param integer $clientApiDelay
* @return Profile
*/
public function setClientApiDelay($clientApiDelay)
{
$this->clientApiDelay = $clientApiDelay;
return $this;
}
/**
* Get clientApiDelay
*
* @return integer
*/
public function getClientApiDelay()
{
return $this->clientApiDelay;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
* @return Profile
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set createdAt to NOW
*
* @return Profile
* @ORM\PrePersist
*/
public function setCreatedAtNow()
{
$this->createdAt = new \DateTime();
return $this;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
* @return Profile
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set updatedAt to NOW
*
* @return Profile
* @ORM\PreUpdate
*/
public function setUpdatedAtNow()
{
$this->updatedAt = new \DateTime();
return $this;
}
/**
* Set user
*
* @param \project\UserBundle\Entity\User $user
* @return Profile
*/
public function setUser(\project\UserBundle\Entity\User $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \project\UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
}
我的 ProfileController.php 文件:
<?php
namespace project\UserBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use project\UserBundle\Entity\Profile;
use project\UserBundle\Form\ProfileType;
/**
* Profile controller.
*
* @Route("/admin/profile")
*/
class ProfileController extends Controller
{
/**
* Lists all Profile entities.
*
* @Route("/", name="admin_profile")
* @Method("GET")
* @Template()
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('projectUserBundle:Profile')->findAll();
return array(
'entities' => $entities,
);
}
/**
* Creates a new Profile entity.
*
* @Route("/", name="admin_profile_create")
* @Method("POST")
* @Template("projectUserBundle:Profile:new.html.twig")
*/
public function createAction(Request $request)
{
$entity = new Profile();
$form = $this->createForm(new ProfileType(), $entity);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('admin_profile_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Displays a form to create a new Profile entity.
*
* @Route("/new", name="admin_profile_new")
* @Method("GET")
* @Template()
*/
public function newAction()
{
$entity = new Profile();
$form = $this->createForm(new ProfileType(), $entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Finds and displays a Profile entity.
*
* @Route("/{id}", name="admin_profile_show")
* @Method("GET")
* @Template()
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('projectUserBundle:Profile')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Profile entity.');
}
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
);
}
/**
* Displays a form to edit an existing Profile entity.
*
* @Route("/{id}/edit", name="admin_profile_edit")
* @Method("GET")
* @Template()
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('projectUserBundle:Profile')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Profile entity.');
}
$editForm = $this->createForm(new ProfileType(), $entity);
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Edits an existing Profile entity.
*
* @Route("/{id}", name="admin_profile_update")
* @Method("PUT")
* @Template("projectUserBundle:Profile:edit.html.twig")
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('projectUserBundle:Profile')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Profile entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createForm(new ProfileType(), $entity);
$editForm->bind($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('admin_profile_edit', array('id' => $id)));
}
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Deletes a Profile entity.
*
* @Route("/{id}", name="admin_profile_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('projectUserBundle:Profile')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Profile entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('admin_profile'));
}
/**
* Creates a form to delete a Profile entity by id.
*
* @param mixed $id The entity id
*
* @return Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder(array('id' => $id))
->add('id', 'hidden')
->getForm()
;
}
}
我已经在 Resources/Profile/show.html 下声明了我的实体,一切正常:例如我的地址:
<th>Address2</th>
<td>{{ entity.address2 }}</td>
我的问题是我有另一个名为 ShowBundle 的包,我想显示该包上的那些实体。例如,当我在该 bundle 上调用 {{ entity.address2 }} 以显示我的地址时,它向我显示:(变量“entity”不存在)
如何在另一个 bundle 的 twig 表单上显示这些配置文件实体,在我的例子中是 ShowBundle?
非常感谢
最佳答案
当然你可以使用{{ app.user.variablename }}
,它是一个全局变量。但是对于其他变量, View 只能显示 Controller 发送给它的数据。这就是 MVC(模型- View - Controller )架构。
变量 entity
仅当您的 Controller 将其发送到 View 时才存在于 Twig View 中。这就是 return array( 'entities' => $entities );
行在您的 ProfileController.php 上所做的,这也是您可以在 Resources/Profile/show.html 中使用它的原因。
如果您想在另一个包中显示一个实体,只需将它从数据库中拉出并将其发送到 View ,就像您在 ProfileController.php 中所做的那样。如果您自己编写了发布的代码,那应该是一件容易的事。
如果您不理解您发布的代码,我建议您学习使用 Symfony。你可以阅读the Book ,这是出色的分步文档。
提示:
将此代码复制到您的其他捆绑 Controller (以 Action()
结尾的方法):
$em = $this->getDoctrine()->getManager(); //get the database manager
$profiles = $em->getRepository('projectUserBundle:Profile')->findAll(); // get the profiles
return array(
'profiles' => $profiles,
); // send data to the view
您将通过模板中的 {{ profiles }}
访问您的个人资料。
关于php - Symfony2 - 从数据库中提取数据并以表格形式显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20983903/
好的,这听起来很简单,但我已经花了几个小时在谷歌上搜索,我只是找不到解决方案,这并不复杂。 我想创建一个包含图像和文本的表格。我希望表格的每一行都具有相同的高度。我希望文本始终从顶部开始。 IE。 \
在我的网站表单上 - 我的出生日期、月份和年份菜单显示在两行上,我希望它们都显示在同一行上。 当我测试代码时,它显示在一行中,所以我相信一定存在宽度问题。 您可以在右侧表格 (incomeprotec
我们需要跟踪和审核生产,本质上我们有很多订单,但我们似乎在途中丢失了一些产品(废品等)。 为了阻止这种情况,我们现在已在 Google 表格上下了订单,并列出了应有的数量,然后员工会写下收到的数量。
我正在转换我的应用程序,以便它适用于 iOS 7。在应用程序的一部分,我有两个搜索栏,每个搜索栏都有一个与之关联的 UISearchDisplayController。当我搜索 UISearchDis
正如标题所说,非固定表格布局是否与类似的 HTML 表格具有相同的性能问题? 最佳答案 非固定表格的问题在于,要确定一列的宽度,必须加载该列的所有单元格。这仅在...... …您有一个包含几千字节或几
我在使用 Javascript 遍历表格并从一行的第一个单元格获取文本时遇到问题。我想获取此单元格的文本,以便我可以将它与其他内容进行比较,如果文本匹配则删除该行。但是,当我尝试获取文本时,实际出现的
我经常发现自己想要制作一个表格表格——一堆行,每一行都是一个单独的表格,有自己的字段和提交按钮。例如,这是一个宠物店应用程序示例——假设这是一个结帐屏幕,您可以选择更新所选宠物的数量和属性,并在结帐前
看过许多UBB代码,包括JS,ASP,JSP的,一直没发现表格的UBB,虽然可以直接用HTML模式实现相同表格功能,但对于某些开放的站点来说开放HTML模式终究是不合适的,故一直想实现表格的UBB。
表格由 table 标签来定义。每个表格均有若干行(由 tr 标签定义),每行被分割为若干单元格(由 td 标签定义)。字母 td 指表格数据(table data),即数据单元格的内容。数据单元格
我有一个 HTML 与 border-radius和使用 position: sticky 的粘性标题看起来像这样: https://codepen.io/muhammadrehansaeed/pen
对于 iPhone 应用程序,我需要以网格格式显示只读表格数据。该数据可能有许多行和列。 我可以使用 UITableView,但问题是数据很可能会非常宽并且需要滚动。 有没有办法将 UITableVi
我知道这里有类似的问题,但我找不到适合我的答案。 我想要的是显示表单“默认”是选择了某些选项(在这种情况下,除了“Ban Appeal”或“Ban Appeal(西类牙语)”之外的所有内容,我希望仅在
天啊! 我想在Flutter中创建以下非常简单的表。基本上是两列文字,左列右对齐,右列左对齐。如果右列具有多个名称,则每一行都将顶部对齐。 左列应自动调整为最大项目的大小(因为每个标题都有翻译字符串)
我们开始构建 SSAS 表格模型,并想知道大多数人是否拥有一个或多个模型。如果有多个,您是否复制每个所需的表,或者是否有办法在模型之间共享表?我想我知道答案,但我希望那些有更多经验的人能够证实我们的发
tl;博士 如何将任意数量的单词分成两列,总是在最后一列中只有最后一个单词,在第一列中包含所有其他单词? =IFS( LEN(C2)-LEN(SUBSTITUTE(C2," ",""))=1, SP
你们知道一个图表或dable,它可以提供一个简短而简洁但仍然完整且相对最新的现有协议(protocol)及其细节的 View ? (即:ZeroMQ、Rendez-Vous、EMS、...所有这些!:
我才刚刚开始开发MFC应用程序,我希望对整个“控件”概念更加熟悉。我在Visual Studio中使用对话框编辑器,到目前为止,我无法找到添加简单表/网格的功能。这对我来说似乎很基础,但是我什至找不到
我需要对一个非常大的表或矩阵执行计算和操作,大约有 7500 行和 30000 列。 矩阵数据将如下所示: 文件编号|字1 |字 2 |字 3 |... |字 30000 |文档类 0032 1 0
我正在使用设计非常糟糕的数据库,我需要在编写查询之前重新调整表格。 以下是我的常见问题: 时间戳已分为两列(一列用于日期,另一列用于时间)。 一些字符串列也被拆分成多个列。 大多数字符串都有固定长度和
我正在尝试显示 $row["name"] 通过 HTML Table 的形式,如下所示: echo " ".$row["name"]." "; 我也从这里获取行变量: $que
我是一名优秀的程序员,十分优秀!