Module was created to make DB records into entities. If you want to create a simple module with simple data you can avoid using this thing, but if your module has larger data this thing will be a life savior. This is practically created to make things easier while Fork CMS team integrates Doctrine 2 into their CMS.
- Core: Fork CMS 3.9.4
Practically any table works if you configure this module for your needs. Main rule that table must have ID field by default, but you can change that.
First of all we need to load proper namespaces
use Common\Modules\Localization\Entity;
We must create our record object, here is an example:a
<?php
namespace Common\Modules\Addresses;
use Common\Modules\Entities\Entity;
/**
* Class Address
* @package Common\Modules\Addresses
*/
class Address extends Entity
{
/**
* Table name of addresses
*
* @var string
*/
protected $_table = 'addresses';
/**
* Query to select single address by ID
*
* @var string
*/
protected $_query = 'SELECT a.* FROM addresses AS a WHERE a.id = ?';
/**
* List of table columns
*
* @var array
*/
protected $_columns = array(
'country',
'city',
'address'
);
/**
* ISO code of a country
*
* @var string
*/
protected $country;
/**
* Name of a city
*
* @var string
*/
protected $city;
/**
* Full address
*
* @var string
*/
protected $address;
/**
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* @param $country
* @return $this
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @param $city
* @return $this
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @param $address
* @return $this
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
}
I will add some examples, how to use this thing.
$address = new Address();
$address->setCountry('Lithuania');
$address->setCity('Kaunas');
$address->save();
$addressArray = $address->toArray();
$address = new Address(array($this->getParameter('address_id', 'int')));
or
$address = new Address();
$address->load(array($this->getParameter('address_id', 'int')));
If you are having any issues, please create issue at Github. Or contact me directly. Thank you.
- e-mail: [email protected]
- skype: vytenizs