この問題に関連する他のいくつかの投稿を見つけましたが、私が望んでいたことを達成できなかったので、すべてを削除して最初からやり直すことにしました...
これはこれまでの私の仕事であり、仕事をしていますが、データは配列にハードコードされて提供されており、それらのデータを取得するにはデータベース接続を作成する必要があります。
私のモジュールクラスには次のものがあります:
public function getViewHelperConfig()
{
return array(
'factories' => array(
'liveStreaming' => function() {
return new LiveStreaming();
},
),
);
}
これは、ビューヘルパーにあるコードです:
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
class LiveStreaming extends AbstractHelper
{
protected $liveStreamingTable;
public function __invoke()
{
$events = array(
'1' => array('name' => 'Event name',
'sport' => 'Soccer',
'time' => '11:30'),
'2' => array('name' => 'Event name',
'sport' => 'Soccer',
'time' => '17:00'),
);
return $events;
//this is what should be used (or something like that) to get the data from the db...
//return array('events' => $this->getLiveStreamingTable()->fetchAll() );
}
public function getLiveStreamingTable()
{
if (!$this->liveStreamingTable) {
$sm = $this->getServiceLocator();
$this->liveStreamingTable = $sm->get('LiveStreaming\Model\LiveStreamingTable');
}
return $this->liveStreamingTable;
}
}
だから、$events
データベースから配列を取得したい。(ZF2 公式チュートリアルの指示に従って) and を作成しましたが、次のステップに進むための助けが必要です。これは、おそらくサービス ロケータに関係しているはずApplication\Model\LiveStreaming
です。Application\Model\LiveStreamingTable