Basic Usage Of Doctrine With CodeIgniter

Lets do a contact form example to understand how to use doctrine ORM within CodeIgniter. Lets create a table on our MySQL database named ‘pd_contact’ as like follows:

mysql contact table schema example

This will generate and entity class as like follows:

<?php
/**
* PdContact
*
* @Table(name=”pd_contact”)
* @Entity
*/
class PdContact
{
/**
* @var integer $id
*
* @Column(name=”id”, type=”integer”, nullable=false)
* @Id
* @GeneratedValue(strategy=”IDENTITY”)
*/
private $id;

/**
* @var string $name
*
* @Column(name=”name”, type=”string”, length=50, nullable=false)
*/
private $name;

/**
* @var string $email
*
* @Column(name=”email”, type=”string”, length=50, nullable=false)
*/
private $email;

/**
* @var string $subject
*
* @Column(name=”subject”, type=”string”, length=100, nullable=false)
*/
private $subject;

/**
* @var text $message
*
* @Column(name=”message”, type=”text”, nullable=false)
*/
private $message;

/**
* Get id
*
* @return integer $id
*/
public function getId()
{
return $this->id;
}

/**
* Set name
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}

/**
* Get name
*
* @return string $name
*/
public function getName()
{
return $this->name;
}

/**
* Set email
*
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}

/**
* Get email
*
* @return string $email
*/
public function getEmail()
{
return $this->email;
}

/**
* Set subject
*
* @param string $subject
*/
public function setSubject($subject)
{
$this->subject = $subject;
}

/**
* Get subject
*
* @return string $subject
*/
public function getSubject()
{
return $this->subject;
}

/**
* Set message
*
* @param text $message
*/
public function setMessage($message)
{
$this->message = $message;
}

/**
* Get message
*
* @return text $message
*/
public function getMessage()
{
return $this->message;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s