Tutorials

This page will list several tutorials found on this blog. Tutorials will be listed either based on what they cover or their difficulty level.

To get you started
Your new to Kohana, you know what it sort of is about but you’d like some help building your first application. You have found the user guide and you know a little about php.

The Blog tutorial is a good start I think. It introduces you to models, controllers and views.


10 Responses to “Using Auto_Modeler to write quicker code”

  1. Trini Says:

    Hi was wondering if the database metadata function list_fields() could have been used to list the tables;


    public function __construct($id = NULL)
    {
    parent::__construct();

    $this->data = $this->db->list_fields($this->table);

    if ($id != NULL)
    {
    // try and get a row with this ID
    $data = $this->db->getwhere($this->table_name, array('id' => $id))->result(FALSE);

    // try and assign the data
    if (count($data) == 1 AND $data = $data->current())
    {
    foreach ($data as $key => $value)
    $this->data[$key] = $value;
    }
    }
    }

    Thanks for the Lib!!!!

  2. Trini Says:

    Just realized that it not just field names but values / Database fields and default values hmm…

  3. zombor Says:

    Yes, you can specify default values in your model as well =)

    The only things that don’t work are things like ‘date’ => time(), since php doesn’t allow you to do that. You can accomplish this in your constructor though. Useful for things like blog posts where you want the post to have the current time.

  4. Trini Says:

    Actually what I wanted to know was if there was an easier to set the table names other than manually like, using the metadata list fields function above does not work, is there any other way!!!

  5. Easylancer Says:

    I was just wondering why is it in the add function it says $this->upload($post); but where is upload in the controller, is that an error or if not can you explain what it does?

  6. zombor Says:

    Ah, that should be do_post(), sorry, a typo! In my controller I named it upload(), but I changed the name for the example.

  7. bennythemink Says:

    Hi zombor,

    one quick question, what if i just wished to update one field and not all the fields in my table?

    it looks as if your save function updates all the fields (i could be mistaken), so if i hadn’t assigned values to all the keys in the data array it would assign the columns in the database table with an empty string.

    am i mistaken?

  8. zombor Says:

    When you do new My_Model($id), it assigns all the rows the value from the database, so if you update that model, it will retain what was in the row to begin with.

    The default values are just there for creating new rows.

  9. Henri Says:

    There are advantages (not being restricted by table-naming conventions is one of them) to using your auto_modeler but the useful __call() function to map find_by_* calls is missing.
    I’ve added the method but limited it to find_by_* queries.

  10. mkjems Says:

    I believe function do_post() contains an error. Var $post is used for two different things. This is correct imho:

    private function do_post($POST_DATA)
    {
    // Insert/update the new item magically
    $post= new Post_Model();
    $post->set_fields($POST_DATA);
    $post->save();
    }

Leave a Comment