drzip28288 2010-11-06 16:30
浏览 35
已采纳

蛋糕php 1.3? 我可以在任何控制器和视图中使用任何模型吗?

My question is that with example. I have to show all categories of books and with checkboxes in a page which I want to be posted to next view without interacting db and there I want to store them in a hidden field in a comma separated string.

Actually I have a tab for find a book. user clicks on it and it has a list of categories of books listed which I get from categories model and used categories controller index function. I want to post user selected categories to next view like where I will take more info regarding user filtration for books it is coming from another model and controller.

actually I want to know what I have to do I want to develop this find a book function.Should I have a model for this and a controller which they use some table for find a book or can I use any model in any controller for this function.

  • 写回答

3条回答 默认 最新

  • dtg7662 2010-11-09 08:25
    关注

    Apart from loading the model itself, You can use a model in a controller other than its own as long as there is a relation between the two models. For example, consider the following relation:

    "Books" Model BelongsTo "Category" Model
    

    In this scenario, you can use

    $this->Book->Category->find() inside BooksController 
    as well as 
    $this->Category->Book->find() inside CategoriesController
    

    Coming to your case, it would help if you post your Database Schema. Nevertheless, to find a book, I assume you are using certain parameters like Categories, Genres, Publishers etc. Assuming each parameter will have it's own database table and model, your search hops would be as follows:

    Page 1: List of Categories with Check boxes for Selection

    • Function - Category Controller's index()
    • View - /app/views/categories/index
    • Passes to - Genres Controller's search()

    Page 2: List of Genres with Check boxes for selection

    • Function - Genre Controller's search()
    • View - /app/views/genres/search
    • Passes to - Publishers Controller's search()

    Page 3: List of Publishers with Check boxes for selection

    • Function - Publisher Controller's search()
    • View - /app/views/publishers/search
    • Passes to - Books Controller's results()

    Page 4: List of Books filtered according to the given parameters

    • Function - Book Controller's results()
    • View - /app/views/books/results
    • Passes to - None

    I tried to be as guiding as possible, leave comment if you are still not clear how to go about searching for books. If you need help with passing data from one controller to another, read the CakePHP Manual (http://book.cakephp.org/view/57/Controller-Methods) or Google using "cakephp passing data from one controller to another" as keywords.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算