PHP code example of divix1988 / laminas-cli-commands
1. Go to this page and download the library: Download divix1988/laminas-cli-commands library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace ModuleName\Controller\ControllerNameController;
class ControllerNameController extends \Laminas\Mvc\Controller\AbstractActionController
{
public function indexAction()
{
}
public function action1Action()
{
}
public function action2Action()
{
}
}
namespace ModuleName\Model;
class ModelNameTable extends AbstractTable
{
protected $resultsPerPage = 10;
public function getBy(array $params = [])
{
$select = $this->tableGateway->getSql()->select();
if (isset($params['id'])) {
$select->where(['id' => $params['id']]);
$params['limit'] = 1;
}
if (isset($params['property1'])) {
$select->where(['property1' => $params['property1']]);
}
if (isset($params['property2'])) {
$select->where(['property2' => $params['property2']]);
}
if (isset($params['limit'])) {
$select->limit($params['limit']);
}
if (!isset($params['page'])) {
$params['page'] = 0;
}
$result = (isset($params['limit']) && $params['limit'] == 1)
? $this->fetchRow($select)
: $this->fetchAll($select, ['limit' => $this->resultsPerPage, 'page' => $params['page']]);
return $result;
}
public function patch(int $id, array $data)
{
if (empty($data)) {
throw new \Exception('missing data to update');
}
$passedData = [];
if (!empty($data['property1'])) {
$passedData['property1'] = $data['property1'];
}
if (!empty($data['property2'])) {
$passedData['property2'] = $data['property2'];
}
$this->tableGateway->update($passedData, ['id' => $id]);
}
public function getById(\Rowset\ModelName $rowset)
{
return parent::saveRow($rowset);
}
public function delete($id)
{
if (empty($id)) {
throw new \Exception('missing comics id to delete');
}
parent::deleteRow($id);
}
}
namespace ModuleName\Model;
class RowsetName
{
public $property1 = null;
public $property2 = null;
public function getProperty1()
{
return $this->property1;
}
public function setProperty1($value)
{
$this->property1 = $value;
return $this;
}
public function getProperty2()
{
return $this->property2;
}
public function setProperty2($value)
{
$this->property2 = $value;
return $this;
}
}