Welcome Guest, Not a member yet? Register   Sign In
Using fancy database introspection to create small web applications - ideas welcome
#12

[eluser]Majd Taby[/eluser]
Here's what i did to solve the same issue:

I wrote a login library, a formgenerator library, and an administration library. Now All i have to do is create a configuration file and it will automatically build the whole backend. Here's how a sample controller might look like:

Code:
<?php
class BuildingListings extends Controller
{    
    function __construct()
    {
        parent::Controller();
        $config = array(
                    'db_table' => 'building_listings',
                    'form_def' => 'building_listings_form.yml',
                    'controller' => 'BuildingListings',
                    'form_pre' => '<div class="formBox">',
                    'form_suff' => '</div><div class="clearer"></div>',
                    'upload_dir' => './uploads/building_listings/',
                    'file_associated_fields' => array('image')
                    );
        $this->load->library('jtabymessages');
        $this->load->library('jtabyadmin',$config);
    }
    function index()
    {
            $query = $this->db->query('SELECT id,file_number,location FROM building_listings');
            $data['listings'] = $query->result_array();

            $this->load->view('building_listings_view',$data);
    }
    function add(){$this->jtabyadmin->add();}
    function edit(){$this->jtabyadmin->edit();}
    function doAdd(){$this->jtabyadmin->doAdd();}
    function doEdit(){$this->jtabyadmin->doEdit();}
    function delete(){$this->jtabyadmin->delete();}
}
?&gt;

and here's what a sample configuration file might look like:

Code:
age:
    class: Image
    label: Image
    attributes:
    value:
file_number:
    class: TextBox
    label: File Number
    attributes:
    value:
business:
    class: TextBox
    label: Business
    attributes:
    value:
location:
    class: TextBox
    label: Location
    attributes:
    value:
years_established:
    class: TextBox
    label: Years Established
    attributes:
    value:
seats:
    class: TextBox
    label: Seats
    attributes:
    value:
licenses_required:
    class: TextBox
    label: Licenses Required
    attributes:
    value:
.
.
.
.
confidential:
    class: CheckBox
    label: Confidential
    attributes:
    value:
agent:
    class: TextBox
    label: Agent
    attributes:
    value:Capital-1.biz
agent_phone:
    class: TextBox
    label: Agent Phone
    attributes:
    value:248-855-6767
agent_fax:
    class: TextBox
    label: Agent Fax
    attributes:
    value:248-855-2266
agent_email:
    class: TextBox
    label: Agent Email
    attributes:
    value:[email protected]

the form generator library currently only handles radio boxes, textboxes, textareas, file upload, and password boxes...it's not done yet.

i was gonna do something that would generate everything based on the db, but I figure that won't be flexible at all and would end up being a headache, this way, it would take me like, 1 hour to do a whole backend. I'd love to share it with you if you were interested.


Messages In This Thread
Using fancy database introspection to create small web applications - ideas welcome - by El Forum - 10-12-2007, 10:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB