تعيين معلمة ورل في إعادة التوجيه في إطار زند الإصدار 2

StackOverflow https://stackoverflow.com//questions/10652001

سؤال

لدي بعد إعادة توجيه البرنامج النصي في وحدة تحكم بلدي (إطار زند 2)

return $this->redirect()->toRoute('default', array(
                        'controller' => 'admin',
                        'action' =>  'index'
));

إعادة التوجيه حاليا إلى localhost/zf2/public/admin/index

كيف يمكنني إعادة توجيه مع معلمة إضافية?

مثل:

localhost/zf2/public/admin/index/update/1

أو localhost/zf2/public/admin/index/page/2

لقد حاولت هذا :

return $this->redirect()->toRoute('default', array(
                        'controller' => 'admin',
                        'action' =>  'index'
                            'param' => 'updated/1'
                        ));

ولكن يتم إعادة توجيهها إلى localhost/ttacounting/public/admin/index/updated%2F1

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

المحلول

هذا واحد هو مثال العمل.البرنامج النصي الطريق

$this->redirect()->toRoute('myaccount', array(
    'controller' => 'admin',
    'action' =>  'index',
    'param1' =>'updated',
    'param2'=>'1'
));

ثم ، تعيين المعلمة في الوحدة النمطية.التكوين.بي إتش بي

'myaccount' => array(
    'type' => 'Segment',
    'options' => array(
    'route'    => '/myaccount[/:action][/:param1][/:param2]',
    'defaults' => array(
            'controller' => 'Main\Controller\MyAccount',
            'action'     => 'index',
        ),
    ),
),

هذا وسوف تجلب لك إلى مياكونتكونترولر ، إندكسكتيون مع بارام1='تحديث' و بارام2='1'.ولكن في حالة المثال الخاص بك ، يجب أن يكون الإجراء تحديث مع اسم المعلمة 'تحديث' وقيمة المعلمة'1'

نصائح أخرى

هذا يعمل بالنسبة لي.

الطريق:

'user_view' => array(
    'type'    => 'Segment',
    'options' => array(
        'route' => '/user/view[/:user_id]',
        'defaults' => array(
            'controller' => 'user',
            'action'     => 'viewUser',
        ),
    ),
), // End of user_view route

وإعادة توجيه من وحدة تحكم:

return $this->redirect()->toRoute('user_view', array('user_id'=>$user_id));

لاحظ أن مفتاح الصفيف في عبارة إعادة التوجيه يتوافق مع مقطع المسار:[ / : معرف المستخدم] = 'معرف المستخدم' =>id معرف المستخدم

هذا البيان الموجهات لك المضيف المحلي / يؤدي / تحرير / 112345:

return $this->redirect()->toRoute('leads', array(
                'action' => 'edit',
                'id' => 112345
            ));

معرف هو المعلمة أتوقع في إديتاكتيون.

آمل أن يساعد.

طريقة أخرى هي تمريرها كمعلمة ثالثة (تم اختبارها على زف 3) ، بدلا من تحديث المسار:

$this->redirect()->toRoute('dashboard', [], ['query' => ['welcome' => 1]]);

حاولت بعض من الحلول المذكورة أعلاه ولكن أيا منهم كانوا يعملون بالنسبة لي.جئت مع ما يلي.

//Return to specific product pricing 
return $this->redirect()->toRoute('showpricing', array('id' => $form_values['id']));


  /* show pricing */
          'showpricing' => array(
              'type' => 'Zend\Mvc\Router\Http\Segment',
              'options' => array(
                  'route'   => '/product/showpricing[?id=:id]',
                  'defaults' => array(
                      'controller' => 'Product\Controller\Product',
                      'action'     => 'showpricing',
                  )
              )
          ),

آمل أن يساعد هذا شخص ما.

جرب هذا المسار بدلا من المسار السابق

return $this->redirect()->toRoute('default', [
    'controller' => 'admin',
    'action' =>  'index'
    'updated' => '1'
]);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top