Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3216784
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:20:06+00:00 2026-05-17T15:20:06+00:00

This is a question I had about working with the Kohana framework, though I

  • 0

This is a question I had about working with the Kohana framework, though I imagine that this is something that could apply to MVC frameworks in general.

Let’s say I have 2 objects/models, an animal object and a farm object, where an animal belongs to a farm, and a farm has many animals. I have a form for creating new animals, and I want to have a drop down to select which farm it belongs to. My question is how best to handle getting the data from the farm table and display it in the form.

Here are a few possible solutions I came up with, but I’m not sure any of them are the best approach. also, I planned on using Kohana’s Form helper library, but that only seems to handle HTML rendering of the forms:

  1. Get the data in the AnimalModel, pass it to the controller, which passes it to the form view. However I’m not sure if this should be the AnimalModel’s responsibility.
  2. Get the data from the FarmModel. My concern here is that is something has a lot of relations, the controller is going to have to start calling a lot of different controllers.
  3. Store all the data that gets passed to the various form methods in the AnimalModel. This would also involve storing things like classes, which seems like it shouldn’t be in the model.
  4. Write some kind of helper Object/Library to store all the form data, and keep it in the Model, or possibly the Controller. Again though, I feel like this would end up with a mixing of display and business logic, which I would like to enjoy.

Another concern I had when designing this is other things that come up with forms, such as validation, and also what to do when I want the form in ‘edit’ mode, and I need to pre-populate it with data from the Model.

What’s the best way to approach writing forms that deal with relations in Kohana/MVC Frameworks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:20:07+00:00Added an answer on May 17, 2026 at 3:20 pm

    Maybe im missing your question but it seems like you’re overcomplicating things. Use a Farm model to get a list of all your farms. Use this list to create a select in your form.

    <select name="farm">
        <option value="1">Farm 1</option>
        <option value="2">Farm 2</option>
        <option value="3">Farm 3</option>
    </select>
    

    Then when you save your animal you have the primary key for the farm it belongs to.

    $animal = $_POST;
    if ( $animal->validate() ) {
        $animal->save(); //saves all your animal data as well as the farm it belongs to.
    }
    else {
        // show your view and display the animal data
    }
    

    your view could do somethign like this

    <label>Animal Name</label><input type="text" value="<?php echo  $animal->getValue('name') ?>">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow-up to a previous question I had about interfaces. I received
We've had this question already, but I want to narrow it down to already
I had this question earlier and it was concluded it was a bug in
This question may sound fairly elementary, but this is a debate I had with
Now I have seen this question in another forum but it didn't had an
The responses I've got to this question have solved the problem I had in
Note: Let me appologize for the length of this question, i had to put
This may seem like a programming 101 question and I had thought I knew
I had the same question as was asked in this thread , i.e. I
(Jeopardy-style question, I wish the answer had been online when I had this issue)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.