私のlayout.phtmlにデータベースカウントを表示するには、ビューヘルパーを使用してthsカウント(dbフィールドに設定)をレンダリングしたいと考えています。
ビュー ヘルパーでデータベース モデルを使用するにはどうすればよいですか?
ヘルパー:
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
class CountHelper extends AbstractHelper
{
protected $count;
public function __invoke()
{
return $this->count();
}
public function setTableCount($sm, $myCountTable)
{
$this->count = $sm->get($myCountTable)->getCount();
return $this->count;
}
}
モジュール
public function getViewHelperConfig()
{
return array(
'factories' => array(
'CountHelper' => function($sm) {
$helper = new \Application\View\Helper\CountHelper();
$helper->setTableCount($sm, 'Application\Model\MyCountTable');
return $helper;
},...
エラー:
キャッチ可能な致命的なエラー: Application\Model\MyeCountTable::__construct() に渡される引数 1 は Zend\Db\TableGateway\TableGateway のインスタンスである必要があります。 /ServiceManager/AbstractPluginManager.php の 175 行目で定義されています。