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/ */

    

divix1988 / laminas-cli-commands example snippets


'laminas-cli' => [
    'commands' => [
        'mvc:controller' => \Divix\Laminas\Cli\Command\ControllerCommand::class,
        'mvc:rowset' => \Divix\Laminas\Cli\Command\RowsetCommand::class,
        'mvc:model' => \Divix\Laminas\Cli\Command\ModelCommand::class,
        'mvc:form' => \Divix\Laminas\Cli\Command\FormCommand::class,
        'mvc:view' => \Divix\Laminas\Cli\Command\ViewCommand::class,
        'mvc:crud' => \Divix\Laminas\Cli\Command\CrudCommand::class,
        'mvc:crud_controller' => \Divix\Laminas\Cli\Command\CrudControllerCommand::class,
        'mvc:crud_view' => \Divix\Laminas\Cli\Command\CrudViewCommand::class,
        'mvc:crud_config' => \Divix\Laminas\Cli\Command\CrudConfigCommand::class,
        'mvc:login_registration' => \Divix\Laminas\Cli\Command\LoginRegistrationCommand::class,
        'mvc:admin' => \Divix\Laminas\Cli\Command\AdminPanelCommand::class,
        'mvc:navigation' => \Divix\Laminas\Cli\Command\NavigationCommand::class,
        'mvc:sitemap' => \Divix\Laminas\Cli\Command\SitemapCommand::class,
        'mvc:mariadb_database_connect' => \Divix\Laminas\Cli\Command\MariaDbCommand::class
    ],
],

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\Form;

use \Laminas\Form\Element;

class NewUserForm extends \Laminas\Form\Form implements \Laminas\InputFilter\InputFilterProviderInterface
{

     const ELEMENT_PROPERTY1 = 'property1';

     const ELEMENT_PROPERTY2 = 'property2';

    public function __construct($name, array $params)
    {
        parent::__construct($name, $params);
        $this->setAttribute('class', 'styledForm');
        
        $this->add([
            'name' => self::ELEMENT_PROPERTY1,
            'type' => 'text',
            'options' => [
                'label' => 'property1'
            ],
            'attributes' => [
                '

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;
    }


}

<p>ModuleName - ViewName</p>

namespace ModuleName;

use Laminas\Router\Http\Segment;
use Laminas\Db\ResultSet\ResultSet;
use Laminas\Db\TableGateway\TableGateway;
use ModuleName\Model\Rowset;
use ModuleName\Model;
use ModuleName\Controller;

return [
    'router' => [
        'routes' => [
            'newUsers' => [
                'type' => Segment::class,
                'options' => [
                    'route' => '/newusers[/:action[/:id]]',
                    'defaults' => [
                        'controller' => Controller\NewUsersController::class,
                        'action' => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'paginator' => [
                        'type' => 'segment',
                        'options' => [
                            'route' => '/[page/:page]',
                            'defaults' => [
                                'page' => 1
                            ]
                        ]
                    ],
                ]
            ]
        ]
    ],
    
    'controllers' => [
        'factories' => [
            Controller\NewUsersController::class => function($sm) {
                $postService = $sm->get(Model\NewUsersTable::class);

                return new Controller\NewUsersController($postService);
            },
        ]
    ],
                    
    'service_manager' => [
        'factories' => [
            'NewUsersTableGateway' => function ($sm) {
                $dbAdapter = $sm->get('Laminas\Db\Adapter\Adapter');
                $config = $sm->get('Config');
                $baseUrl = $config['view_manager']['base_url'];
                $resultSetPrototype = new ResultSet();
                $identity = new Rowset\NewUser($baseUrl);
                $resultSetPrototype->setArrayObjectPrototype($identity);
                return new TableGateway('newusers', $dbAdapter, null, $resultSetPrototype);
            },
            Model\NewUsersTable::class => function($sm) {
                $tableGateway = $sm->get('NewUsersTableGateway');
                $table = new Model\NewUsersTable($tableGateway);
                return $table;
            },
        ]
    ],
                    
    'view_manager' => [
        'template_map' => [
            'module-name/new-users/index' => __DIR__ . '/../view/NewUsers/index.phtml',
            'module-name/new-users/edit' => __DIR__ . '/../view/NewUsers/edit.phtml',
            'module-name/new-users/add' => __DIR__ . '/../view/NewUsers/add.phtml',
            'module-name/new-users/pagination' => __DIR__ . '/../view/NewUsers/pagination.phtml',
        ],
    ]
];


[root]/module/[moduleName]/src/Controller/LoginController.php
[root]/module/[moduleName]/src/Controller/RegisterController.php
[root]/module/[moduleName]/src/Model/UserModel.php