tree em
tree em

Reputation: 21721

Got errors When try load xml zend framework 2

I have create a controller:

    public function testAction() {
        $hml = '<div>
                    <table>
                        <tr>
                            <td class="foo">
                                <div>
                                    Lorem ipsum <span class="bar">
                                        <a href="/foo/bar" id="one">One</a>
                                        <a href="/foo/baz" id="two">Two</a>
                                        <a href="/foo/bat" id="three">Three</a>
                                        <a href="/foo/bla" id="four">Four</a>
                                    </span>
                                </div>
                            </td>
                        </tr>
                    </table>
                    </div>';
​​​​​​​​        use Zend\Dom\Query;
        $dom = new Query($html);
        $results = $dom->execute('.foo .bar a');
        return new ViewModel(array(
            'results' => $results,
        )
        );
    }

My View

<!-- Begin page content -->
<div id="container">
<div class="pane ui-layout-center">
    <?php 
    print_r($results);
    ?>
</div>

But I when I run that controller I got the message:

Cannot query; no document registered

anybody know what is the problem?

Upvotes: 0

Views: 91

Answers (1)

OlegKrivtsov
OlegKrivtsov

Reputation: 750

It does not work, because you have a typo in variable names. You store HTML in the $hml variable, however pass a non existing $html variable to the constructor of the Query class.

Upvotes: 2

Related Questions