我已经尝试过多次将symfony应用程序与数据库连接,但我没有从中获取任何输出。我已经展示了整个MVC代码。我需要插入并选择它。 以下是我的实体文件。
namespace Atpl\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* TblSignup
*
* @ORM\Table(name="tbl_signup")
* @ORM\Entity
*/
class TblSignup
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="fname", type="string", length=255, nullable=false)
*/
private $fname;
/**
* @var string
*
* @ORM\Column(name="lname", type="string", length=255, nullable=false)
*/
private $lname;
/**
* @var string
*
* @ORM\Column(name="company_name", type="string", length=255, nullable=false)
*/
private $companyName;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255, nullable=false)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="web_url", type="string", length=255, nullable=false)
*/
private $webUrl;
/**
* @var string
*
* @ORM\Column(name="phone", type="string", length=20, nullable=false)
*/
private $phone;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=50, nullable=false)
*/
private $password;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set fname
*
* @param string $fname
* @return TblSignup
*/
public function setFname($fname)
{
$this->fname = $fname;
return $this;
}
/**
* Get fname
*
* @return string
*/
public function getFname()
{
return $this->fname;
}
/**
* Set lname
*
* @param string $lname
* @return TblSignup
*/
public function setLname($lname)
{
$this->lname = $lname;
return $this;
}
/**
* Get lname
*
* @return string
*/
public function getLname()
{
return $this->lname;
}
/**
* Set companyName
*
* @param string $companyName
* @return TblSignup
*/
public function setCompanyName($companyName)
{
$this->companyName = $companyName;
return $this;
}
/**
* Get companyName
*
* @return string
*/
public function getCompanyName()
{
return $this->companyName;
}
/**
* Set email
*
* @param string $email
* @return TblSignup
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set webUrl
*
* @param string $webUrl
* @return TblSignup
*/
public function setWebUrl($webUrl)
{
$this->webUrl = $webUrl;
return $this;
}
/**
* Get webUrl
*
* @return string
*/
public function getWebUrl()
{
return $this->webUrl;
}
/**
* Set phone
*
* @param string $phone
* @return TblSignup
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set password
*
* @param string $password
* @return TblSignup
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
}
这是我的Controller(DefaultController.php)文件。
/**
* @Route("/",name="atpl_front_signup")
* @Template()
* @return type
*/
public function signUpAction(Request $request)
{
$entity = new TblSignup();
$form = $this->createForm($entity);
$form->handleRequest($request);
if($form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('atpl_signup_create', array('id'=>$entity->getId())));
}
return array('entity'=>$entity,'form'=>$form->createView());
}
我的twig文件包含几个块,我需要从中插入数据并需要在数据库中显示数据。
{% block section_signup %}
<section id="signup">
<form method="POST" id="signupform" action="{{path('atpl_signup_create')}}">
<div class="signup-body">
<div class="container">
<div class="col-md-12">
<div class="col-md-6 block">
<h1>Sign Up Now</h1>
<h4><font><img src="{{asset('bundles/wpapp/images/user-icon.png')}}"></font><font>Your Contact Information</font></h4>
<div class="tr">
<label>First Name</label>
<input type="text" name="fname" id="fname">
</div>
<div class="tr">
<label>Last Name</label>
<input type="text" name="lname" id="lname">
</div>
<div class="tr">
<label>Company Name</label>
<input type="text" name="compName" id="compName">
</div>
<div class="tr">
<label>Email</label>
<input type="text" name="email" id="email">
</div>
<div class="tr">
<label>Confirm Email</label>
<input type="text" name="confEmail" id="confEmail">
</div>
<div class="tr">
<label>Website URL</label>
<input type="text" name="webUrl" id="webUrl">
</div>
<div class="tr">
<label>Phone</label>
<input type="text" name="phone" id="phone">
</div>
<div class="tr">
<label>Password</label>
<input type="password" name="password" id="password">
</div>
<div class="tr">
<label>Confirm Password</label>
<input type="password" name="confPass" id="confPass">
</div>
<div class="tr">
<input type="checkbox" class="check">
<label class="label2">Click Here to Automatically Remember Your Password on This Computer</label>
</div>
<div class="tr text-center">
<font>(click only once and allow time to process)</font>
<input type="submit" class="btn" value="Create Account">
</div>
</div>
<div class="col-md-6 block">
<div class="moneyback">
<div class="inn">
<div class="icon"><img src="{{asset('bundles/wpapp/images/money-icon.png')}}"></div>
<div class="text">
<h3>MONEY BACK GUARANTEE</h3>
</div>
</div>
</div>
<div class="text-center">
<a href="#"><img src="{{asset('bundles/wpapp/images/icon1.png')}}"></a>
<a href="#"><img src="{{asset('bundles/wpapp/images/icon2.png')}}"></a>
<a href="#"><img src="{{asset('bundles/wpapp/images/icon3.png')}}"></a>
<a href="#">Privacy Policy</a>
</div>
</div>
</div>
</div>
</div>
</form>
<div class="page-scroll arrow2">
<a href="#contact" class="arrow animated bounce"></a>
</div>
</section>
{% endblock %}
答案 0 :(得分:0)
我没有阅读所有代码,但如果您的控制器中没有全部&#34;使用&#34;那么您的代码就无法运行。必要:我留下了文件:http://symfony.com/fr/doc/current/book/doctrine.html