Welcome Guest, Not a member yet? Register   Sign In
Customizable CRUD
#11

[eluser]PedroGrilo[/eluser]
[quote author="suashi" date="1203741930"]
.......
but I want... KISS!
Big Grin
.......[/quote]
Isn't that the main reason why we all chose CI over all the other frameworks in the first place? Wink

Looking forward for 0.2!
#12

[eluser]Atasa[/eluser]
Hey guys this is getting interesting...
My point of view is that we can discuss different ways and alternatives for ever.
Lets start from what we have already.
We have CI.
Then we check whether is OK this tool to work on.
Remember this is not an easy job.
I have looked for quite sometime now in frameworks, html generators, template systems etc.
The first thing that clicks to your mind when you see a framework is the philosophy it is based on.
If we have decided to use CI so lets see how far we can go, and if that is expensive too.
I also thing that some logic sould go also at the database it self.
One good example is the mysql database in MySql.

suashi you can try the following as well:

Code:
<?php

class Welcome extends Controller {
    
    
    function Welcome()
    {
        parent::Controller();
        $this->load->library('table');
        $this->load->helper('form');
        $this->load->helper('url');    
        
    }
    
    function index()
    {
    
    $form = array(
        'Row1' => array(
            'FIELD_NAME' => 'field1',
            'FORM_CAPTION' => 'Text for field1',
            'DEFAULT_VALUE' => 'enter text here',
            'EDIT_TYPE' => 'input',
            'LOOKUP_COMMAND' => ''
        ) ,
        'Row2' => array(
            'FIELD_NAME' => 'field2',
            'FORM_CAPTION' => 'Text for field2',
            'DEFAULT_VALUE' => 'Please make a Selection',
            'EDIT_TYPE' => 'select',
            'LOOKUP_COMMAND' => array ('key1'=>'value1','key2'=>'value2','key3'=>'value3')
        ) ,
        'Row3' => array(
            'FIELD_NAME' => 'field3',
            'FORM_CAPTION' => 'Please write your Details',
            'DEFAULT_VALUE' => '',
            'EDIT_TYPE' => 'textarea',
            'LOOKUP_COMMAND' => ''
        )
    );

    $oform = form_open('email/send')."\n";    
    $oform .= $this->table->set_heading('Name', 'Value');
    
    function BuildForm($myform)    
    {
        $mytable = &get;_instance();
        foreach ($myform as $array)
        {
            switch ($array['EDIT_TYPE'])
            {
                case 'input':
                $options = array('name' => $array['FIELD_NAME'], 'value' => $array['DEFAULT_VALUE'], 'maxlength' => '50');
                $mytable->table->add_row($array['FORM_CAPTION'], form_input($options));
                break;

                case 'textarea':
                $options = array('name' => $array['FIELD_NAME'],'value' => $array['DEFAULT_VALUE'],'rows' => '7','cols' => '50');
                $mytable->table->add_row($array['FORM_CAPTION'], form_textarea($options));
                break;

                case 'select':
                $mytable->table->add_row($array['FORM_CAPTION'], form_dropdown($array['FIELD_NAME'], $array['LOOKUP_COMMAND']));
                break;                                
            }
        }
    
    }
    BuildForm($form);
    
    $oform.= $this->table->generate();
    $oform.= form_reset('myreset', 'Reset Fields');
    $oform.= form_submit('mysubmit', 'Submit Post!');
    $oform.= "\n <br/>" . form_close() ;
    echo $oform;
    }//endIndex
    
    
}
?&gt;

It's small sample of binding an array to a form generator class.
for the sake of the example I have created a subfunction and used &get;_instance() method.
you can just run it by it self and see the results.

Very easy right?
#13

[eluser]adamp1[/eluser]
What do people thing about using table layout for forms? Me personally, I don't think you should. A table is for displaying tabular data, a form isn't this. It also means you can't easily change how the form looks. E.g move the field name above the input box instead of it being to the left.

What do people think? Coz I think this is a major point of having a customizable CRUD system.
#14

[eluser]xwero[/eluser]
I have to agree with adamp1. Customizable means views too. But a simple solution would be to work with partial views.
#15

[eluser]adamp1[/eluser]
You could even go as far to having a separate views for each type of form field. That way you can create your own form elements. With it then being able to handle dynamic data that would be quite powerful (IE adding descriptions to a field value). Suppose best form of crud would be to output it to files so you can tweak it.
#16

[eluser]gyo[/eluser]
adamp1 + xwero: yeah guys I agree with you, actually the original CRUD library comes with absolutely NO layout informations (infact without a css provided in the example the form will show up in a default way, ready to be styled).


atasa: I'll try your code and think about a table-mapping feature! Although I'm still oriented to an automated dynamic.



EDIT: Only the "Read" method which displays tabular data comes with a table layout, but I'd like to allow its style customization too.

Btw I still can't get to release a 0.2 version cause I'd like to implement some stuff and didn't have the time to get it working as I wish!
#17

[eluser]gyo[/eluser]
Hello!

I published CRUD 0.2, the downloads are in the first post of the thread, thankss!
#18

[eluser]Atasa[/eluser]
OK suashi I will have a look at your progress...

For adamp1 + xwero
As you know we don't deal with views yet.
OK we can display the form in a division instead of a table.
I am also in favor of tabless layouts but actually wanted to try the table class in this case.
I will correct that soon.
You may also want to provide ccs and template views for the different views we gonna use if you like

Cheers
#19

[eluser]gyo[/eluser]
I'm sorry I did I mistake with fields, please download it again, thanks!
#20

[eluser]PedroGrilo[/eluser]
suashi, thanks for your work on this.

I'm really in-love with the simplicity of your lib.

Keep it up!




Theme © iAndrew 2016 - Forum software by © MyBB