سؤال

لدي التعليمات البرمجية التالية في بلدي زف 2 تحكم:

<?php
namespace Accounting\Controller;

use Zend\Mvc\Controller\ActionController,
Zend\View\Model\ViewModel,
Accounting\Model,
Zend\Paginator,
Accounting\Scripts\CMSTranslator;

class AdminController extends ActionController {

protected $translator;

public function setTranslator(CMSTranslator $translator) {
    $this->translator = $translator;
    return $this;
}

public function __construct(\Doctrine\ORM\EntityManager $em,CMSTranslator $translator) {
    $this->em = $em;

    //$this->translator = new \Zend\Translator\Translator('ArrayAdapter', __DIR__ . '/../../../lang/lang-fa.php', 'fa');
    $this->translator = $translator;

    \Zend\Registry::set('tr', $this->translator);
    // now you can use the EntityManager!
}

كما ترون أنا باستخدام وحدة زند \ المترجم.
أريد إضافته إلى العرض في منشئ وحدة التحكم الخاصة بي.لقد حاولت بالفعل:

return ViewModel(array('tr'=>$translator));

لكن هذا لا يعمل.

الرجاء المساعدة.

هل كانت مفيدة؟

المحلول 2

الحلول النهائية module.config.php giveacodicetagpre.

نصائح أخرى

إضافة متغير فئة خاصة private $viewModel.ثم إنشاء فيوموديل في كونستروتور الخاص بك ، إضافة أي متغيرات:

$this->viewModel = new ViewModel();
$this->viewModel->tr = $translator;

ثم العودة $this->viewModel من وظيفة العمل الخاص بك.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top