Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Automatic data grid generation from ORM object - display data EASILY
  • Hello chaps I'd like to introduce something that I've been working on with Thomas Stevens.
    I'm not sure if any of you are familiar with using Magento's admin but it has a kick ass grid controller that allows model instances to be displayed in tables that utilises pagination, filtering, reordering, actions and mass actions (apply an action to selected items). We've created a very similar thing that is also a fuel package! The package itself fully complies with the MVC design pattern by keeping views separate from the class itself, which means you can override the view (or even assign a different view for a one-off rendering) - giving you full control over what it looks like. For the grid to work it does require an instance of the Kohana ORM object, which it manipulates according to what the user has specified (ie should a certain field be filtered or should the results be ordered by a certain field). The grid can take an object of two or more Kohana ORM instances joined together. It's stupidly easy to setup and works automagically. So many grids that are floating around have (among many problems) a rendering problem - sometimes you don't want to see the EXACT data from the database.
    In this grid, every column goes through a renderer class that has two functions, render_column() and translate_filter(). These functions are pretty well the reverse of each other (because if you change the appearance of data the user is going to try and filter by the data they recognise, not the raw data).
    You can add your own renderer and and configure a column to use it. You can configure mass actions for selected items that appear automatically when needed (the massactions redirects you and posts a form with your request with the primary keys of the records selected in an array) The grid has many functions and options that can be used to configure it for tailored use. The grid has a little bit of work to go before we release it, however it's coming along really well and due to the stable nature of the Kohana ORM, we've not found any big problematic bugs in the grid. This is only one of several components of the TJS Package that will be made available open-source so you can download it through OIL or github. Thoughts?
  • Hi Ben. I hope this message finds you well. I installed the Spark package- looks great so far. Is there a quick start guide?
  • @akian0 thanks for the feedback! I've not made any documentation yet as I've not fully completed the first version of the plugin, but I will surely make lots of documentation including screen casts as soon as it's all done. as a quick teaser see the following:
    $grid = Grid::factory('customers_grid', Model_Customer::init()->with('country'))
       ->add_column('first_name', array(
        'index'  => 'first_name',
        'label'  => 'First Name',
       ))
       ->add_column('last_name', array(
        'index'  => 'last_name',
        'label'  => 'Last Name',
       ))
       ->add_column('created_at', array(
        'index'  => 'created_at',
        'label'  => 'Created At',
        'renderer' => 'date',
        'width'  => 100,
        'align'  => 'center',
       ))
       ->add_column('region_name', array(
        'index'  => 'region:name',
        'label'  => 'Region',
       ))
       ->add_massaction('create_invoice', array(
        'action' => 'test/url/mass_create_invoice',
        'label'  => 'Create Invoice',
       ))
       ->render();
    

    Be sure you merge the contents of the assets folder with the assets folder in your public folder./Users/bencorlett My mate and I will have some screen casts done up very soon. we use screen flow and because we're both registered apple devs we're using mac os x lion, and screen flow isn't working with mac os x lion so we're going to have to do it on another computer.
  • Ben Corlett wrote on Sunday 17th of April 2011:
    @akian0 thanks for the feedback! I've not made any documentation yet as I've not fully completed the first version of the plugin, but I will surely make lots of documentation including screen casts as soon as it's all done. as a quick teaser see the following:
    $grid = Grid::factory('customers_grid', Model_Customer::init()->with('country'))
       ->add_column('first_name', array(
        'index'  => 'first_name',
        'label'  => 'First Name',
       ))
       ->add_column('last_name', array(
        'index'  => 'last_name',
        'label'  => 'Last Name',
       ))
       ->add_column('created_at', array(
        'index'  => 'created_at',
        'label'  => 'Created At',
        'renderer' => 'date',
        'width'  => 100,
        'align'  => 'center',
       ))
       ->add_column('region_name', array(
        'index'  => 'region:name',
        'label'  => 'Region',
       ))
       ->add_massaction('create_invoice', array(
        'action' => 'test/url/mass_create_invoice',
        'label'  => 'Create Invoice',
       ))
       ->render();
    

    Be sure you merge the contents of the assets folder with the assets folder in your public folder./Users/bencorlett My mate and I will have some screen casts done up very soon. we use screen flow and because we're both registered apple devs we're using mac os x lion, and screen flow isn't working with mac os x lion so we're going to have to do it on another computer.
    Fantastic! Looking forward to the screen casts.
  • I've updated this package to work with RC2.1 The code's on GitHub at https://github.com/ShonM/Spark
  • Dream Forge wrote on Wednesday 27th of April 2011:
    Hi there,
    Your grid package looks really nice!
    To give it a try, I used something like your teaser code example above.
    (With the latest version of Spark from the github repo, Fuel RC2 and fuel's orm package).
    $grid = Grid::factory('customers_grid', Model_Customer::init())
       ->add_column('first_name', array(
        'index'  => 'first_name',
        'label'  => 'First Name',
       ))
       ->add_column('last_name', array(
        'index'  => 'last_name',
        'label'  => 'Last Name',
       ))
       ->add_column('created_at', array(
        'index'  => 'created_at',
        'label'  => 'Created At',
        'renderer' => 'date',
        'width'  => 100,
        'align'  => 'center',
       ))
       ->add_massaction('create_invoice', array(
        'action' => 'test/url/mass_create_invoice',
        'label'  => 'Create Invoice',
       ))
       ->render();
    

    Then assuming that the $grid variable now contains some View (the container), I passed it strait away from my controller to some view :
    $this->response->body = $grid;
    

    But this gave me the error : "[Error]: Call to a member function get_identifier() on a non-object".
    (PKGPATH/spark/views/grid/table.php @ line 30)
    when doing
    <table class="<?=$grid->get_identifier()?>" ...
    

    What am I doing wrong?

    Got the same error :(
  • Hey I'm not sure what's happening with that but I'll check it out in the morning (it's night here in Australia) I probably did something dumb and pushed to gothic, I've not pushed all of the latest changes to Github Sorry for not getting back for so long but I'll have an answer for you guys in about 12 hours :)
  • Ben Corlett wrote on Sunday 1st of May 2011:
    Hey I'm not sure what's happening with that but I'll check it out in the morning (it's night here in Australia) I probably did something dumb and pushed to gothic, I've not pushed all of the latest changes to Github Sorry for not getting back for so long but I'll have an answer for you guys in about 12 hours :)

    Awesome, thanks man :)
  • Hello there. Any news on this amazing grid?
  • Also interested in this. Any chance you could post the code as-is on github or something so I could fork?
  • Hi Guys, If you can hold on for just a day or two more we'll be releasing the Grid code on gihub. We've rewritten a lot of it in the past week so it is driver based for the ORM. This means you can either use our port of Kohana's ORM or the new Fuel ORM with it. We'll keep you posted. Thomas
  • These are really good news, Thomas and Ben! I'm watching this thread from it's birthday!:) Good luck and thank you
  • That sounds awesome! Kind regards.
  • Hello, this is something really amazing. Never seen something similar, but often was thinking about such a beauty.
    Maybe it won't fit in front end, but for cms/backend this is freaking awesome. As for now I'm using phpAR package for my future project, but will be switching to native orm, when Dan and others are done with it. What do you think, it won't be an issue if I use orm - for frontend and your port of kohanna orm - for backend? Thanks
  • Hi, Approximately when do plan to integrate the support for joining tables? Thanks
  • Hey, The grid has support for joining tables with the Orm (I think with the DB driver too, can't remember if I added it). Just set the index property of a column to be like: (for this example, we're getting a User model that belongs to a Meta model)
    'meta.first_name', which will correspond to $user->meta->first_name If you want to add more support you're welcome and you can send through a pull request.
  • Hey, using the newest dev builds..but when i use the "teaser" code I get Fuel\Core\Fuel_Exception [ Error ]: Invalid method call. Method init does not exist. anyone?
  • Our port of Kohana's ORM is in a different namespace to fuel's activerecord so it should be fine. It should be noted that the only reason we're using kohana's ORM over fuel's AR is because kohana's ORM is better overall but it was missing the magic get and set and find by methods (which we've added with our port). As soon as Fuel's AR is up to par we'll modify the grid controller so you can use it instead.
  • Sounds very good. thanks for an explanation. We'll be waiting for a relese, since as I udnerstood it's in the development now. Good work guys :) As I can see in the last days, ORM is getting more and more attention, so within 2-4 weeks I think it'll be ready to go! Good luck everywhere!
  • Hi Ben, sorry to be digging up an old topic, but I just stumbled onto this one. If I wanted to use your grid, would you point me to the 1.0 master or 1.1 master tree? I will be the only one using the grid since it is for a private project... thanks for your answer!
  • Hey mate, The trees match the FuelPHP version - so assuming you're on 1.1/master of FuelPHP, 1.1/master of Spark. Basically, each time the FuelPHP changes I might need to change the Spark API, and it's great when you're updating your git submodules, because you can do: git submodule foreach git pull origin 1.1/master (This is of course if you haven't the upstream remote branch for the branch of your submodule through git branch --set-upstream 1.1/master origin/1.1/master. If you have, you can just call git submodule foreach git pull origin). Anyway, you can visit http://spark.bencorlett.com/ to see more usage. I've updated and added heaps of features since I updated those examples, if you get stuck I'd suggest coming on irc.freenode.net and visit the #fuelphp channel. I'm usually on there.
  • Hi Ben! Any updates?
  • Hey, how is it going Ben? maybe you have some ready-to-go usage examples? Thanks!
  • Hi I'm in the process of rewriting a new version of the grid and other classes. It can be found at https://github.com/bencorlett/Spark.git Spark - Ignite your Fuel! Anyway it should be up and running this week sometime (the rewrite on github has only just started so it's VERY bare, but bare with me {pun intended} and it'll be ready very soon)
  • Hi there,
    Your grid package looks really nice!
    To give it a try, I used something like your teaser code example above.
    (With the latest version of Spark from the github repo, Fuel RC2 and fuel's orm package).
    $grid = Grid::factory('customers_grid', Model_Customer::init())
       ->add_column('first_name', array(
        'index'  => 'first_name',
        'label'  => 'First Name',
       ))
       ->add_column('last_name', array(
        'index'  => 'last_name',
        'label'  => 'Last Name',
       ))
       ->add_column('created_at', array(
        'index'  => 'created_at',
        'label'  => 'Created At',
        'renderer' => 'date',
        'width'  => 100,
        'align'  => 'center',
       ))
       ->add_massaction('create_invoice', array(
        'action' => 'test/url/mass_create_invoice',
        'label'  => 'Create Invoice',
       ))
       ->render();
    

    Then assuming that the $grid variable now contains some View (the container), I passed it strait away from my controller to some view :
    $this->response->body = $grid;
    

    But this gave me the error : "[Error]: Call to a member function get_identifier() on a non-object".
    (PKGPATH/spark/views/grid/table.php @ line 30)
    when doing
    <table class="<?=$grid->get_identifier()?>" ...
    

    What am I doing wrong?
  • thanks Ben for your efforts, we are all waiting for this baby to come up

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion