codeigniterでのORMの実装を試みています。
環境設定は、一つ一つlibに必要なものをおとしてきてエラーは出力されていない状態になりました。
そこから実装を確認したいのですが、方法がわかりません。
http://codesamplez.com/development/using-doctrine-with-codeigniter
上記のサイトを参考にしながらすすめているのですが
なにをcontrollerに記述するのか、modelに記述するのかがわからないです。
ORMが実装できているということ簡単に確認できる方法を教えていただきたいです
宜しくお願い致します。
model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); require_once(APPPATH."models/PdContact.php"); /** * manipulates data and contains data access logics for Enity 'User' * * @final Homemodel * @category models * @author Md. Ali Ahsan Rana * @link http://codesamplez.com */ class Homemodel extends CI_Model { /** * @var \Doctrine\ORM\EntityManager $em */ var $em; public function __construct() { parent::__construct(); $this->em = $this->doctrine->em; } /** * Add contact messages to database * @param array $contact_form * @return bool */ function add_message() { /** * @var PdContact $contact */ $contact = new PdContact(); $contact->setName($this->input->post("name")); $contact->setEmail($this->input->post("email")); var_dump($contact); try { //save to database $this->em->persist($contact); $this->em->flush(); } catch(Exception $err){ die($err->getMessage()); } return true; } } ?>
controller
<?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; } }
あなたの回答
tips
プレビュー