Codeigniter:嵌套视图中的逻辑

发布于 2024-11-29 04:36:17 字数 347 浏览 3 评论 0原文

我有一个 template.php,其中包括页眉、页脚和主要内容。

然而,在我的 template.php 中,我想添加一个购物车小部件,它利用购物车类、表单类和会话类。

我希望小部件最初是购物车之前的一个表单,它从用户收集简单数据(姓名、电子邮件、一些下拉框和复选框信息)并将这些参数发送到将使用的会话(使用 CI_SESSIONS 存储在数据库中)按应用程序(相关产品)(根据复选框选择显示产品)和购物车。

我希望逻辑能够通过小部件进行处理,而无需重新加载整个页面(AJAX/JS?),然后在用户浏览应用程序时使用会话来存储购物车数据。

谁能推荐任何阅读材料或图书馆,让我找到正确的答案?

问候,

I have a template.php that includes a header, footer and main content.

However, in my template.php, I would like to add a shopping cart widget that utilises the shopping cart class, the form class and obviously the session class.

I want the widget to intially be a form before the cart which gathers simple data from the user (name, email, some dropdown boxes and checkbox information) and sends these parameters to a session (stored in the database using CI_SESSIONS) which will be used by the application (related products) (show products based on checkbox selections) and the cart.

I want the logic to process through the widget without having to reload the entire page (AJAX/JS?) and then use the session to store the cart data as the user browses through the application.

Can anyone recommend any reading materials or libraries to put me in the right direction to an answer?

Regards,

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

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

发布评论

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

评论(2

山人契 2024-12-06 04:36:17

根据我对您问题的理解,我认为您可以将购物车小部件实现为部分视图。我通常将 template.php 构造得非常简单,除了一些需要存在的东西。这是一个例子
layout/template.php

<html>
<head>
<?php $this->load->view('layout/head'); ?>
</head>
<body>
  <div class='header'>
    <?php $this->load->view('layout/body_header'); ?>
  </div>

  <div class='content'>
    <?php echo $content; ?>
  </div>

  <div class='widget'>
     <?php $this->load->view('cart/widget'); ?>
  </div>

  <div class='footer'>
    <?php $this->load->view('layout/body_footer'); ?>
  </div>
</body>

然后您可以在 cart/widget.php 中使用 ajax,以便您可以在视图部分中调用所需的函数。

From what I understand in your problem, I think you can implement your shopping cart widget as a partial view. I usually structure my template.php to be very bare except for some stuff that need to be there. Here is an example
layout/template.php

<html>
<head>
<?php $this->load->view('layout/head'); ?>
</head>
<body>
  <div class='header'>
    <?php $this->load->view('layout/body_header'); ?>
  </div>

  <div class='content'>
    <?php echo $content; ?>
  </div>

  <div class='widget'>
     <?php $this->load->view('cart/widget'); ?>
  </div>

  <div class='footer'>
    <?php $this->load->view('layout/body_footer'); ?>
  </div>
</body>

Then you can use ajax in your cart/widget.php so you can call functions that you need in your view partial.

淡忘如思 2024-12-06 04:36:17

使用 codeigntier HMVC 创建视图部分。然后,您可以为小部件创建一个单独的模块,在其中可以处理表单、会话等。

您还可以使用 Ajax 刷新特定模块(在 div 中加载),以便分布在多个选项卡上的网站的所有页面都具有相同的视图。

Use codeigntier HMVC to create view partials. Then you can have a separate module for the widget where you can handle forms, sessions etc.

You can also use Ajax to refresh the specific module (loaded in a div) so that all pages of your website spread across multiple tabs have the same view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文