Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Beginner's question: views and data
  • Hi,

    I'm new to fuel and got stuck with views. How can I pass an array to the _form view
    so I can work with it there?

    print_r works for the passed array in the target view (drafts/create) but if I use print_r in the _form I get this exception


    Undefined variable: users
    APPPATH/views/drafts/_form.php @ line 19



    The idea behind this is that I want to add a select field 'owner' for the admin user and would build it using that array.
    Here's the code:
    Model:
    public static function get_users() {
    $results = DB::select('id', 'username')
    ->from('users')
    ->as_assoc()
    ->execute();

    return $results;
    }


    Controller
    $results = Model_Draft::get_users();

    $users = array();
    foreach($results as $item)
    {
    $users[$item['id']] = $item['username'];
    }

    $view = View::forge('drafts/create');
    $view->set('users', $users);
    $this->template->title = 'Drafts';
    $this->template->content = $view;

  • HarroHarro
    Accepted Answer
    I assume you're talking about generated views? Where the forum for edit and create is in a third, separate view?

    In that case, open the edit or create view file. In there you'll find the View::forge() or render() call that loads the _form view. You will need to use set() again (or something similar) to pass $users on to the _form view.

    There is no inheritance between views.

Howdy, Stranger!

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

In this Discussion