Welcome Guest, Not a member yet? Register   Sign In
What is best structure for a big application?
#8

[eluser]Edemilson Lima[/eluser]
Quite long thread... I find an example there which simplify the thing, but still is not the perfect world. The products.php controller could be:

Code:
<?php
class Products extends Controller {

    function Products() {
        parent::Controller();
        $this->load->helper('form');
        $this->load->model('categories');
        $this->load->model('products');

        $header['menu']=$this->load->view('menu_view','',true);
        $categories=$this->model->categories->list();
        $lateral['lateral']=$this->load->view('categories_view',$categories,true);
        $this->data['header']=$this->load->view('header_view',$header,true);
        $this->data['lateral']=$this->load->view('lateral_view',$lateral,true);
        $this->data['footer']=$this->load->view('footer_view','',true);
    }

    function index() {
        // generates a list of products with links to add, update or remove
        $products=$this->model->product->list();
        $this->data['section']='Product List';
        $this->data['contents']=$this->load->view('products_view',$products,true);
        $this->load->view('main_view',$this->data);
    }

    function add() {
        // return a form to include new products, etc.
        $product_data=product_add_function();
        $this->data['section']='Product - Include';
        $this->data['contents']=$this->load->view('product_include_view',$product_data,true);
        $this->load->view('main_view',$this->data);
    }

    function update($id) {
        // generates a form filled with a product data
        $product_data=product_update_function($id);
        $this->data['section']='Product - Update';
        $this->data['contents']=$this->load->view('product_update_view',$product_data,true);
        $this->load->view('main_view',$this->data);
    }

    function remove($id) {
        // ask to remove and deletes products from the database
        $product_data=product_remove_function();
        $this->data['section']='Product - Remove';
        $this->data['contents']=$this->load->view('product_remove_view',$product_data,true);
        $this->load->view('main_view',$this->data);
    }

}
?>

In this example, the common views be in the constructor and are passed to the main_view by $this->data variable.

Well, I could place these common views in a function and just load it everytime I need.

I take a brief look at the examples there, but what I really want (I guess) was a way to load controllers within views or load constructors instead. We could have something like:

Code:
$this->load->constructor('[folder/]file','function'[,$data][,true/false]);

Such method could load the file and execute the function, passing the optional $data array and print or return the output to the caller constructor or view. Loaded constructors could also load another views or constructors.

Well, I don't know the impact of this or even if it is possible, but I think it could solve this issue.


Messages In This Thread
What is best structure for a big application? - by El Forum - 01-14-2008, 07:09 AM
What is best structure for a big application? - by El Forum - 01-14-2008, 07:24 AM
What is best structure for a big application? - by El Forum - 01-14-2008, 09:45 AM
What is best structure for a big application? - by El Forum - 01-17-2008, 12:43 AM
What is best structure for a big application? - by El Forum - 01-17-2008, 06:33 AM
What is best structure for a big application? - by El Forum - 01-17-2008, 06:34 AM
What is best structure for a big application? - by El Forum - 01-17-2008, 07:06 AM
What is best structure for a big application? - by El Forum - 01-17-2008, 11:55 AM
What is best structure for a big application? - by El Forum - 01-17-2008, 02:14 PM
What is best structure for a big application? - by El Forum - 01-17-2008, 02:15 PM
What is best structure for a big application? - by El Forum - 01-17-2008, 03:20 PM
What is best structure for a big application? - by El Forum - 01-17-2008, 03:27 PM
What is best structure for a big application? - by El Forum - 01-17-2008, 06:55 PM
What is best structure for a big application? - by El Forum - 01-17-2008, 07:14 PM
What is best structure for a big application? - by El Forum - 01-19-2008, 08:20 PM
What is best structure for a big application? - by El Forum - 01-20-2008, 10:40 AM
What is best structure for a big application? - by El Forum - 01-21-2008, 11:19 AM
What is best structure for a big application? - by El Forum - 02-02-2008, 01:35 PM
What is best structure for a big application? - by El Forum - 02-02-2008, 03:53 PM
What is best structure for a big application? - by El Forum - 02-02-2008, 05:15 PM
What is best structure for a big application? - by El Forum - 02-02-2008, 05:51 PM
What is best structure for a big application? - by El Forum - 02-03-2008, 06:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB