我如何连接我的应用程序与数据库…



我已经尝试了太多次连接我的symfony应用程序与数据库,但我没有得到任何输出。这里我展示了整个MVC代码。我需要为它插入和选择。以下是我的实体文件。

namespace AtplFrontBundleEntity;
use DoctrineORMMapping as ORM;
/**
 * TblSignup
 *
 * @ORMTable(name="tbl_signup")
 * @ORMEntity
 */
class TblSignup
{
    /**
     * @var integer
     *
     * @ORMColumn(name="id", type="integer", nullable=false)
     * @ORMId
     * @ORMGeneratedValue(strategy="IDENTITY")
     */
    private $id;
    /**
     * @var string
     *
     * @ORMColumn(name="fname", type="string", length=255, nullable=false)
     */
    private $fname;
    /**
     * @var string
     *
     * @ORMColumn(name="lname", type="string", length=255, nullable=false)
     */
    private $lname;
    /**
     * @var string
     *
     * @ORMColumn(name="company_name", type="string", length=255, nullable=false)
     */
    private $companyName;
    /**
     * @var string
     *
     * @ORMColumn(name="email", type="string", length=255, nullable=false)
     */
    private $email;
    /**
     * @var string
     *
     * @ORMColumn(name="web_url", type="string", length=255, nullable=false)
     */
    private $webUrl;
    /**
     * @var string
     *
     * @ORMColumn(name="phone", type="string", length=20, nullable=false)
     */
    private $phone;
    /**
     * @var string
     *
     * @ORMColumn(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;
    }
}

这是我的控制器(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());
}

我的分支文件包含几个块,我需要从中插入数据,并需要在数据库中显示数据。

{% 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 %}

我没有阅读所有的代码,但你的代码不能工作,如果在你的控制器你没有所有的"使用"必要的:我留给你的文档:http://symfony.com/fr/doc/current/book/doctrine.html

相关内容

  • 没有找到相关文章

最新更新