CakePHP:使用查找和可容纳的未定义变量

发布于 2024-11-02 18:31:16 字数 1927 浏览 0 评论 0原文

遇到另一个问题,我似乎无法找到可能导致的任何信息。

我正在声明变量 $makes ,但在视图中找不到它。

这是我当前的代码:

function makemodel($id = null) {
    $this->Make->id = $id;

    $makes = $this->Make->find('all', array(
        'conditions' => array('id' => $id),
        'contain' => array('Makemodel' => array('Road'))
        )
    );
}

} ?>

我也尝试过: $this->set->('makes',$this->Make->find(script here));

任何建议将不胜感激谢谢!

除了cakePHP的书之外还有其他参考资料吗?

大批 ( [0] =>大批 ( [制作] =>大批 ( [id] => 1 [url_make] =>斯巴鲁 [品牌名称] =>斯巴鲁 [MakeOrigin] =>日本 【总结】=>

            )

        [Makemodel] => Array
            (
                [0] => Array
                    (
                        [id] => 1
                        [ModelName] => Impreza WRX
                        [make_id] => 1
                        [Road] => Array
                            (
                                [0] => Array
                                    (
                                        [id] => 3
                                        [makemodel_id] => 1
                                        [RoadTypeID] => 1
                                        [name] => Dirt
                                    )

                                [1] => Array
                                    (
                                        [id] => 4
                                        [makemodel_id] => 1
                                        [RoadTypeID] => 2
                                        [name] => Snow
                                    )

                            )

                    )

            )

    )

Running into another issue that I just seem cant to find any information what could be causing.

I am declaring variable $makes and inside the view its not finding it.

here is my current code:

function makemodel($id = null) {
    $this->Make->id = $id;

    $makes = $this->Make->find('all', array(
        'conditions' => array('id' => $id),
        'contain' => array('Makemodel' => array('Road'))
        )
    );
}

}
?>

I have also tried this: $this->set->('makes',$this->Make->find(script here));

Any advice would be appreciated thanks!

Are there any reference material other than cakePHP's book?

Array
(
[0] => Array
(
[Make] => Array
(
[id] => 1
[url_make] => subaru
[MakeName] => Subaru
[MakeOrigin] => Japan
[Summary] =>

            )

        [Makemodel] => Array
            (
                [0] => Array
                    (
                        [id] => 1
                        [ModelName] => Impreza WRX
                        [make_id] => 1
                        [Road] => Array
                            (
                                [0] => Array
                                    (
                                        [id] => 3
                                        [makemodel_id] => 1
                                        [RoadTypeID] => 1
                                        [name] => Dirt
                                    )

                                [1] => Array
                                    (
                                        [id] => 4
                                        [makemodel_id] => 1
                                        [RoadTypeID] => 2
                                        [name] => Snow
                                    )

                            )

                    )

            )

    )

)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝天白云 2024-11-09 18:31:16

假设 find 调用正常工作,您必须使用 set() 方法将数据从控制器传递到视图。

    function makemodel($id = null) {
    $this->Make->id = $id;

    $makes = $this->Make->find('all', array(
        'conditions' => array('id' => $id),
        'contain' => array('Makemodel' => array('Road'))
        )
    );
    $this->set(compact('makes'));
}

Assuming that the find call is working correctly, you have to pass the data from your controller to your view using the set() method.

    function makemodel($id = null) {
    $this->Make->id = $id;

    $makes = $this->Make->find('all', array(
        'conditions' => array('id' => $id),
        'contain' => array('Makemodel' => array('Road'))
        )
    );
    $this->set(compact('makes'));
}
小猫一只 2024-11-09 18:31:16

find 返回正确的结果吗?

function makemodel($id = null) {
    $makes = $this->Make->find('all', array(
        'conditions' => array('id' => $id),
        'contain' => array('Makemodel' => array('Road'))
        )
    );
    $this->set('makes', $makes);
}

Is find returning correct results?

function makemodel($id = null) {
    $makes = $this->Make->find('all', array(
        'conditions' => array('id' => $id),
        'contain' => array('Makemodel' => array('Road'))
        )
    );
    $this->set('makes', $makes);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文