简体   繁体   English

多部分调查-如何在Laravel 4.0中制作?

[英]Multi part survey - How to make in Laravel 4.0?

I am currently busy with a application that should work like this: 我目前正忙于一个应如下工作的应用程序:

We have several students that want to take extra classes of a certain subject. 我们有几个学生想参加某门学科的额外课程。 So I made a view with 11 subjects they can take. 因此,我对他们可以选择的11个主题进行了介绍。 Vary from History, Biology, Geography, etc they can choose what they like. 他们可以根据历史,生物学,地理等方面的不同而有所选择。 So after choosing a few subjects, I want to take them to the first subject they choose, after that the second, third etc. (they choose the subjects by checkboxes) 因此,在选择了几个主题之后,我想将它们带到他们选择的第一个主题,然后再选择第二个,第三个,等等(他们通过复选框选择主题)

I know I have to be working with a cookie if the student is not logged in. And a session if the student needs to login. 我知道,如果学生未登录,我必须使用cookie。如果学生需要登录,则必须使用会话。 So, I chose for a login page ofcourse. 因此,我选择了课程的登录页面。 How do I get the views viewed (in order) that the student has chosen? 我如何(按顺序)查看学生选择的视图? Do I put it in a controller? 是否将其放入控制器中? Do I use Input? 我要使用输入吗? Or set functions in the routes.php file? 还是在routes.php文件中设置功能? I would like to have some like this: 我想要一些这样的东西:

If checkboxvalue='checked'=>'subject'
{
    then show View('subject');
} 

It's almost like a multi-part survey, where following views depend greatly on what you selected in the view before it 这几乎就像一个多部分调查,其中以下视图在很大程度上取决于您在其之前选择的视图

How to make that in Laravel? 如何在Laravel中做到这一点? Thanks in advance for any tips/advice/link. 在此先感谢您的任何提示/建议/链接。 I really need some help with this 我真的需要一些帮助

Store the values in the session. 将值存储在会话中。

  1. The user goes to a route which directs to a controller method: CourseController::getCourses() . 用户转到的路线指向控制器方法: CourseController::getCourses() This method renders a view with a form & a bunch of checkboxes. 此方法使用表单和一堆复选框来呈现视图。

  2. The user fills out their course selections by checking the checkboxes & submitting. 用户通过选中复选框并提交来填写他们的课程选择。 This request is routed to a postCourses() method. 该请求被路由到postCourses()方法。

  3. The postCourses() method constructs the list of courses, saves it in the session, and redirects to the page for the first course in the list (eg. getChem100() ). postCourses()方法构造课程列表,将其保存在会话中,然后重定向到列表中第一门课程的页面(例如getChem100() )。 Imagine you have a list like this: $courses = array("chem100", "psyc100") . 假设您有一个这样的列表: $courses = array("chem100", "psyc100")

  4. The getChem100() method renders a view. getChem100()方法呈现一个视图。 That view includes a "Next" button which posts the form data (whatever they entered for their Chem 100 class) to postChem100() . 该视图包括一个“下一步”按钮,该按钮将表单数据(无论他们为Chem 100类输入了什么) postChem100()postChem100()

  5. The postChem100() method does whatever it needs to do with the data and redirects to the next course in the list (in this case getPsyc100() ). postChem100()方法将对数据进行任何处理,然后重定向到列表中的下一个课程(在本例中为getPsyc100() )。

  6. And so on, until all the data is gathered... 依此类推,直到收集了所有数据...

This is a very minimal example and there are many ways it could be improved. 这是一个非常小的示例,可以通过多种方法进行改进。 For example, you'll avoid a lot of duplicate code if you structure your data in such a way that there's only one getCourseInfo() method, one view template, and one postCourseInfo() method. 例如,如果您以只有一个getCourseInfo()方法,一个视图模板和一个postCourseInfo()方法的方式构造数据,就可以避免大量重复的代码。 Those methods would take the course ID as an argument. 这些方法将课程ID作为参数。 This kind of optimization will depend on your data structure and is beyond the scope of this answer. 这种优化将取决于您的数据结构,并且超出了此答案的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM