dongshenchi5364 2012-10-30 10:01
浏览 65
已采纳

如何在CodeIgniter中设计一些复杂的应用程序? [关闭]

Im writing web application based on database with many tables with many relations.

For example i have table with [Items], which has many relations.

Each [Item] has one [Group]

Each [Item] has multiple [Ingredients]

Each [Ingredient] has one [Type]

My code is going out of control. I wrote "edit_item_record" form that is filled with fields like "name" or "id", but i have problems with dropdowns and sub-items.

I dont know how to create form that has everything related with [Item] on one page (Name, Group, Ingredients). Submitting form like this may need multiple inserts or updates on many tables. How to handle this?

Does anyone saw any tutorial for CodeIgniter that describes how to design application bigger than blog with 1 table and 2 fields?

  • 写回答

1条回答 默认 最新

  • duanniubeng2265 2012-10-30 10:30
    关注

    You're not going to get this kind of thing through a tutorial, you need to take what you learned in the blog type tutorials and apply it to your situation. In my application simply adding a product can affect as many as 7 tables.

    This is more a question about workflow than anything. You need to sit down with a pen and a pad and map out how things work, how your tables relate and the flow to add the data. Before you start coding you need to understand how to add data, which tables require information from others before you can insert etc. Take for example a simple product, you have basic data in the product table and another table for product images. Obviously in this case you'd need to insert the product table first to get an id to add to the images table. Yes you are going to end up with multiple inserts, in fact when adding a new member my routine inserts to one table twice due to the way the data works.

    Take your time and map it out. This is a situation where no one tutorial is going to help, it's about you looking at your tables and data flow logically and putting it together.

    As to putting all the data on one form that is the easy part. Simply pull the data in your controller using a query with joins. Something along these lines.

    Controller:

    $data['products'] = $this->product->getAllProductDetails($productId);
    

    Model:

    $this->db->where('productId',$productId);
    $this->db->join('product_images','product_images.productId=products.productId');
    $this->db->join('manufacturers','manufacturers.manufacturerId=products.productId');
    $this->db->get('products');
    

    The above would pull all the product, product images and manufacturer information into the variable $products for you to use in your view. Then on your save button you would have another controller function that would individually call saves (insert or update, personally I have a save function that decides which is required) for each of those tables

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么apriori的运行时间会比fp growth的运行时间短呢
  • ¥15 帮我解决一下膳食平衡的线性规划模型的数据实例
  • ¥40 万年历缺少农历,需要和阳历同时显示
  • ¥250 雷电模拟器内存穿透、寻基址和特征码的教学
  • ¥200 比特币ord程序wallet_constructor.rs文件支持一次性铸造1000个代币,并将它们分配到40个UTXO上(每个UTXO上分配25个代币),并设置找零地址
  • ¥15 关于Java的学习问题
  • ¥15 如何使用chatgpt完成文本分类任务?
  • ¥15 已知速度v关于位置s的等式,怎么转化为已知位置求速度v的等式
  • ¥15 我有个餐饮系统,用wampserver把环境配置好了,但是后端的网页却进去,是为什么,能不能帮远程一下?
  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"