Zend Framework 2请求

时间:2014-07-07 01:12:39

标签: php zend-framework zend-framework2

我有问题请求在条件中选择:

注意:未定义的变量:idSous in C:\瓦帕\ WWW \ ZF2 \模块\ Categorie \ SRC \ Categorie \模型\ CategorieTable.php 在第26行

<?php
namespace Categorie\Model;

use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql\Select;

class CategorieTable
{    
    protected $tableGateway;

    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
    }

    //fonction qui permet d'afficher tous la table "Article" 
    public function fetchAll($idSous)
    {   

        $idSous  = (int) $idSous;
        $resultSet = $this->tableGateway->select(function (Select $select) {
        $select->columns(array('titre_art', 'description_art'))
        ->join('sous_categorie', 'articles.id_sous_categorie = sous_categorie.id_sous_categorie')
        ->where->like('sous_categorie.id_sous_categorie', $idSous);
        });
        return $resultSet;
    }

}

但是当我使用这个requet时,它会运行:

<?php
namespace Categorie\Model;

use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql\Select;

class CategorieTable
{    
    protected $tableGateway;

    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
    }

    public function fetchAll($idSous) {
        $idSous  = (int) $idSous;
        $resultSet = $this->tableGateway->select("id_sous_categorie = $idSous");
        var_dump($resultSet);
        return $resultSet;
    }
}

为什么我的第二个请求会运行但不是第一个?

我需要在此控制器中获取$ idSous

<?php
namespace Categorie\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class AgroalimentaireController extends AbstractActionController
{   
    protected $categorieTable;

    public function indexAction($idSous = 2)
    {
        return new ViewModel(array(
            'categorie' => $this->getAnnoncesTable()->fetchAll($idSous),
        ));
    }

    public function getAnnoncesTable()
    {   
        //permet de recupéré les champs de la table "Article"
        if (!$this->categorieTable) {
            $sm = $this->getServiceLocator();
            $this->categorieTable = $sm->get('Categorie\Model\CategorieTable');
        }
        return $this->categorieTable;
    }
}

0 个答案:

没有答案