Json code Array 2 Array (ZF2)

Controller :

$arrYear = array(“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “11”, “12”);
$arrNameYear = array(“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”);

$temp = array();
foreach($arrNameYear as $n => $name):

foreach($arrYear as $y => $year):

$temp[$y] = [$arrNameYear[$y].””,””.$arrYear[$y]];

endforeach;

endforeach;

View : (phtml)

<?php echo json_encode($temp);?>

Output :

[[“Jan”,”1″],[“Feb”,”2″],[“Mar”,”3″],[“Apr”,”4″],[“May”,”5″],[“Jun”,”6″],[“Jul”,”7″],[“Aug”,”8″],[“Sep”,”9″],[“Oct”,”10″],[“Nov”,”11″],[“Dec”,”12″]]

Credit by : www.iDevelopper.net

Doctrine Insert,Edit,Del

$entityManager = $this->getServiceLocator()->get(‘Doctrine\ORM\EntityManager’);

$post = $entityManager->getRepository(‘Saletarget\Entity\StAlloc2Sup’);

Insert :

$post = new StAlloc2Sup();
$entityManager->persist($post);

$post->setAreaId($postAllocTemp->getAreaId());
$post->setSupId($postAllocTemp->getSupId());
$post->setProductNodeId($postAllocTemp->getProductNodeId());
$post->setCycleNumber(1);
$post->setAllocYear($cur_date);

$entityManager->flush();

Edit :

$post = $entityManager->getRepository(‘Saletarget\Entity\StTempAlloc2Sup’)->find($postAllocTemp->getAllocIdTemp());

$post->setStatusName(‘approve’)

$entityManager->flush();

Del :

$post = $entityManager->getRepository(‘Saletarget\Entity\Comment’)->find($num);

$entityManager->remove($post);

$entityManager->flush();

Credit by : www.iDevelopper.net

DQL join tables (Doctrine)

module/module name/view/module name/list.phtml

<tbody>
<!–?php foreach($strollingsalearea as $post) : ?>
<tr>
php echo $post->getNameEng();?>”>getNameTh();?>
</tr>
<!–?php endforeach; ?>
</tbody>

Controller :

$entityManager = $this->getServiceLocator()->get(‘doctrine.entitymanager.orm_default’);
$dql = “SELECT c FROM Saletarget\Entity\CfgRoleResp a
JOIN Saletarget\Entity\StRollingSaleArea b WITH a.areaId = b.areaId
JOIN Saletarget\Entity\CfgProductHc c WITH b.productNodeId = c.productNodeId WHERE a.roleId = “. $num .” “;
$query = $entityManager->createQuery($dql);
$data = $query->getResult();

Entity CfgRoleResp :

class CfgRoleResp
{
/**
* @var integer
*
* @ORM\Column(name=”resp_id”, type=”integer”, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy=”IDENTITY”)
*/

private $respId;

/**
* @var integer
*
* @ORM\Column(name=”role_id”, type=”integer”, length=10, nullable=false)
*/
private $roleId;

/**
* @var integer
*
* @ORM\Column(name=”area_id”, type=”integer”, length=10, nullable=false)
*/
private $areaId;

}

Entity StRollingSaleArea :

class StRollingSaleArea
{
//strategy=”IDENTITY”
//strategy=”AUTO”
/**
* @var integer
*
* @ORM\Column(name=”Id”, type=”integer”, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy=”IDENTITY”)
*/
private $rollingId;

/**
* @var integer
*
* @ORM\Column(name=”area_id”, type=”integer”, length=10, nullable=false)
*/
private $areaId;

/**
* @var integer
*
* @ORM\Column(name=”product_node_id”, type=”integer”, length=10, nullable=false)
*/
private $productNodeId;

}

Entity CfgProductHc :

class CfgProductHc
{
/**
* @var integer
*
* @ORM\Column(name=”node_id”, type=”integer”, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy=”IDENTITY”)
*/
private $productNodeId;

}

Credit by : http://www.iDevelopper.net