0

私の現在のルートファイル:

<?php

return array(
    'controllers' => array(
        'invokables' => array(
           'Customers\Controller\Customers' => 'Customers\Controller\CustomersController',
        ),
    ),

    // The following section is new` and should be added to your file
    'router' => array(
        'routes' => array(
            'customers' => array(
                'type'    => 'Segment',
                'options' => array(
                    'route'    => '/customers[/:action][/:id]',
                    'constraints' => array(
                        'id'     => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Customers\Controller\Customers',
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'strategies' => array(
            'ViewJsonStrategy',
        ),
    ),
); 

データを取得するために機能する方法

私の現在のコントローラー:

<?php

namespace Products\Controller;

// <-- Add this import

use Zend\Mvc\Controller\AbstractRestfulController;
use Products\Model\Products;          // <-- Add this import
use Products\Form\ProductsForm;       // <-- Add this import    // <-- Add this import
use Zend\View\Model\JsonModel;
use Zend\Db\TableGateway\TableGateway;

class ProductsController extends AbstractRestfulController {

    protected $productsTable;
    private $returnMsg = array();

    public function getList($data) {
        $data = array();
       $results = $this->getproductsTable()->select();
        foreach ($results as $result) {
            $data[] = $result;
       }

        return new JsonModel(array(
            'data' => $data,
        ));
    }

    public function get($data) {
      //  $products = $this->getProductsTable()->getProducts($id);

        return new JsonModel(array(
            'data' => '',
        ));
    }

    public function payment_plans($data) {
      //  $products = $this->getProductsTable()->getProducts($id);

        return new JsonModel(array(
            'data' => '',
        ));
    }

    public function create($data) {

        $form = new ProductsForm();
        $products = new Products();
        $form->setInputFilter($products->getInputFilter());
        $form->setData($data);
        if ($form->isValid()) {
            $returnMsg = 'ok';
            $products->exchangeArray($form->getData());

            date_default_timezone_set("UTC");
            $cdate = date("Y-m-d H:i:s", time());
            $data = array(
                'prd_main_id' => (isset($data['prd_main_id'])) ? $data['prd_main_id'] : null,
                'prd_main_title' => (isset($data['prd_main_title'])) ? $data['prd_main_title'] : null,
                'prd_main_description' => (isset($data['prd_main_description'])) ? $data['prd_main_description'] : null,
                'prd_main_created_at' => (isset($cdate)) ? $cdate : null,
            );

            $this->getproductsTable()->insert($data);
            /*
              $cus_email = $data['cus_email'];
              $results = $this->getCustomersTable()->select(array('cus_email' => $cus_email));
              foreach ($results as $result) {
              $datar[] = $result;
              }
              if (empty($datar)) {
              $this->getCustomersTable()->insert($data);
              $cus_email = $data['cus_email'];
              $resultsv = $this->getCustomersTable()->select(array('cus_email' => $cus_email));
              foreach ($resultsv as $resultv) {
              $datav = $resultv;
              }
              $returnMsg = $datav;
              } else {
              $returnMsg = array('errors' => "email address already exists ! ");
              }
             */
        } else {


            $returnMsg = 'ofgk';
        }

        return new JsonModel(array(
            $data,
        ));
    }

    public function update($id, $data) {
        $data['id'] = $id;
        $products = $this->getProductsTable()->getProducts($id);
        $form = new ProductsForm();
        $form->bind($products);
        $form->setInputFilter($products->getInputFilter());
        $form->setData($data);
        if ($form->isValid()) {
            $id = $this->getProductsTable()->saveProducts($form->getData());
        }

        return new JsonModel(array(
            'data' => $this->get($id),
        ));
    }

    public function delete($id) {
        $this->getProductsTable()->deleteProducts($id);

        return new JsonModel(array(
            'data' => 'deleted',
        ));
    }

    public function getproductsTable() {
        if (!$this->productsTable) {
            $this->productsTable = new TableGateway('products', $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter'));
        }
        return $this->productsTable;
    }

} 
4

1 に答える 1

0
      'name' => array(
            'type'    => 'Segment',
            'options' => array(
        'route'    => '/products[/[:id]]/payment_plans[/[:payment_id]]',
                'defaults' => array(
                    '__NAMESPACE__' => 'Template\Controller',
                    'id'         => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'payment_id'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                ),
            ), 
于 2013-09-13T08:51:08.597 に答える