PHP和代码流... [英] PHP and code flow...

查看:43
本文介绍了PHP和代码流...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.我正在编写一个用于个人业务的Web应用程序.这是一项艰巨的工作,将处理发票,付款,时间安排等.我预计这将需要6个月或一年的大部分时间才能用完我的业余时间.

我做了几次错误的开始,但似乎总是以意大利面条式的代码告终.我的主要障碍是使程序了解其当前状态.例如,有一个页面可以添加新客户或新供应商,并且它们可以正常工作.有时在输入发票时,可能会发生供应商,客户或工作地点或不存在的情况.该应用程序.需要转移到新客户"页面,获取数据并返回原始点.输入新客户时,可能会发生客户使用以前从未输入过的银行的情况,因此需要转移到新银行"页面,然后回溯到开始的地方.

到让问题更明确-请考虑银行使用的网络界面.我必须登录才能执行任何操作.如果我正在进行交易,会话超时,那么我将再次进入登录页面,但是在输入登录详细信息后,我不会再次进入主菜单...它带我到交易结束的地方.在幕后的某个地方,一个聪明的程序员跟踪了我的工作,因此可以在会话的不同时间点重复使用登录页面.那是我需要做的事情.

我一直在使用会话变量和页面中的一些隐藏变量来提供帮助,但是随着程序的发展,它变得繁琐而混乱.有无数的if或s和-规则和规则的例外.

任何人都可以就如何集成和跟踪所有不同的子项提供一些好的通用建议吗? -大型应用程序的组件是这样的吗?

请先谢谢.
Angus

Hi all. I''m writing a web app for personal business use. It''s a big job and will handle invoicing, payments, time scheduling and so on. I expect it will take the better part of 6 months or a year to finish in my spare time.

I''ve made a couple of false starts but seem always to end up with spaghetti code. My major obstacle is keeping the program aware of what it''s current status is.

For example, there''s a page to add a new customer, or a new supplier and they work fine. sometimes while entering an invoice it happens that the supplier or the customer or work location or something that does not exist. The app. needs to divert to the "New customer" page, get the data and return to the original point. While entering the new customer it might happen that the customer uses a bank that''s never been entered before and so it needs to divert to the "New Bank" page and then backtrack to where it started.

To make the problem clearer - please consider the web-interface my bank uses. I have to log in to do anything at all. If I''m half way through a transaction and the session times out, I''m taken to the log-in page again, but after entering the login details I don''t go to the main menu again ... it takes me to where I left off with the transaction. Somewhere behind the scenes a clever programmer kept track of what I was doing, so the log-in page can be re-used over and over at different points in a session. That''s the kind of thing I need to do.

I''ve been using session variables and some hidden variables in the pages to assist but as the program grows it becomes cumbersome and confusing. There''s an endless list of if''s or''s and''s - rules and exceptions to rules.

Can anybody give some good generic advice about how to integrate and track all the various sub-components of a large application like this?

Thanks in advance.
Angus

推荐答案

好问题.您可以通过多种方式执行此操作.

我将使用存储在会话变量中的数组("
Good Question. There are many ways you can do this.

I would use an array stored in a session variable ("


任务"-参见下文).我还要让每个页面在保存过程中保存数据,并使用唯一ID引用所有内容-这样,如果您半途而后意识到需要执行其他操作,则可以关闭并执行其他操作,数据将被存储.

我还建议将存储页面数据到数据库的代码放入一个函数中,以便您可以从任何其他文件中引用它.这样,如果您的表单有5个可能的退出点-您只需要编写一次存储数据的代码.

当您到达将其重定向到新页面的位置时,将当前页面添加到任务数组:

tasks" - see below). I''d also have each page save data as you go along and refer to everything using a Unique ID - so that if you get halfway through and realise you need to do something else you can go off and do something else and the data will be stored.

I also suggest putting the code that stores a page''s data to the database into a function so that you can reference it from any other file. This way, if your form has 5 possible exit points - you only need to write the code that stores the data once.

When you reach a point where they will be redirected to a new page add the current page to the tasks array:


tasks =


这篇关于PHP和代码流...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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