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

Difference between host name and domain name

  • hostname is the name given to the end-point (the machine in question)
    • and will be used to identify it over DNS if that is configured
  • domain is the name given to the ‘network
    • it will be required to reach the network from an external point (like the Internet)

It is usually written in the form,

hostname.domain.com — for example

If you are in (say) a college campus named called ‘The-University‘,
and its domain is called ‘theuniversity.org‘,
a machine on the campus network called ‘mymachine‘ would be addressed as, ‘mymachine.theuniversity.org‘.

If you were trying to connect to this machine from your home network,
you would address it with that full name.
The domain part would reach you to the campus network
and the hostname would let you reach the exact machine in the campus.
I am avoiding the details of IP Addressing and gateways here.

For this reason, while accessing the machine from another machine within the campus
may work with just the hostname (mymachine) without the use of the domain name.

To taken an analogy, if you are in the same city, the street name suffices.
But, to address a place in another city, you would usually add the city name after the street.