ZF2 - 如何检查有孩子的路线是否存在

时间:2016-08-03 20:24:59

标签: zend-framework

鉴于这条路线:

    'country' => array(
            'type' => 'Zend\Mvc\Router\Http\Segment',
            'options' => array(
                'route' => '/1country',
                'defaults' => array(
                    'controller' => 'Index',
                    'action'     => 'country',
                    'country_id'     => '5',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                        'city' => array(
                            'type' => 'Zend\Mvc\Router\Http\Segment',
                            'options' => array(
                                'route' => '/1city',
                                'defaults' => array(
                                    'controller' => 'Index',
                                    'action'     => 'city',
                                    'city_id'     => '4',
                                ),
                            ),
                        ),

             ),
        ),

如果我这样做:

$this->getServiceLocator()->get('Router')->hasRoute('country'); //true
$this->getServiceLocator()->get('Router')->hasRoute('country/city'); //false

虽然两者都应该是真的......有什么想法吗?

1 个答案:

答案 0 :(得分:2)

试试这个:

import threading
import time
import sys
import serial
import os
import time

    def Task1(ser):

    while 1:

        print "Inside Thread 1"
        ser.write('\x5A\x03\x02\x02\x02\x09') # Byte ArrayTo Control a MicroProcessing Unit
        b = ser.read(7)
        print b.encode('hex')
        print "Thread 1 still going on"
        time.sleep(1)


def Task2(ser):

    print "Inside Thread 2"
    print "I stopped Task 1 to start and execute Thread 2"
    ser.write('x5A\x03\x02\x08\x02\x0F')
    c = ser.read(7)
    print c.encode('hex')
    print "Thread 2 complete"


def Main():
    ser = serial.Serial(3, 11520)
    t1 = threading.Thread(target = Task1, args=[ser])
    t2 = threading.Thread(target = Task2, args=[ser])
    print "Starting Thread 1"
    t1.start()
    print "Starting Thread 2"
    t2.start()

    print "=== exiting ==="

    ser.close()

if __name__ == '__main__':

    Main()