蛋糕的PHP 1.3?我可以在任何控制器和视图中使用任何模型吗? [英] cake php 1.3? Can I Use any model in any controller and views?

查看:97
本文介绍了蛋糕的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.

推荐答案

只要两个模型之间存在关系,就可以在控制器以外的模型中使用模型。例如,考虑以下关系:

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

对于您的情况,如果您发布数据库架构,这将有所帮助。不过,要找到一本书,我假设您使用的是某些参数,例如Categories,Genres,Publishers等。假设每个参数都有自己的数据库表和模型,则您的搜索跃点如下:

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:

第1页:带有选择框的类别列表

Page 1: List of Categories with Check boxes for Selection


  • 功能-类别控制器的index()

  • 视图-/ app / views / categories / index

  • 传递给-类型控制器的search()

第2页:带有选中复选框的流派列表

Page 2: List of Genres with Check boxes for selection


  • 功能-流派控制器的search()

  • 查看-/ app / views / genres / search

  • 传递给-Publishers Controller的search()

第3页:带有选中复选框的发布者列表

Page 3: List of Publishers with Check boxes for selection


  • 功能-发布者控制器的功能search()

  • 查看-/ app / views / publishers / search

  • 传递给-图书管理员的结果()

第4页:根据给定参数过滤的图书清单

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


  • 功能-图书控制器的results()

  • 查看-/ app / views / books / results

  • 传递给-无

我试图尽可能地提供指导,如果您仍然不清楚如何查找书籍,请发表评论。如果您需要将数据从一个控制器传递到另一个控制器的帮助,请阅读CakePHP手册(http://book.cakephp.org/view/57/Controller-Methods)或使用 cakephp将数据从一个控制器传递到另一个控制器作为Google的手册。关键字。

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.

希望这会有所帮助:)

这篇关于蛋糕的PHP 1.3?我可以在任何控制器和视图中使用任何模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆