Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Variables in the view
  • Hi guys! I can't seem to get the variable in the view file. in controller
        $this->template->title = "Users";
            $this->template->content = View::factory('users/create')
                    ->set('countries', Helper::countries(),false);
    

    If I dump the Helper::countries() in the controller it shows the array contents so i know the array has values. view
    <?php echo Form::select('country_id','', $countries); ?> I get this error message:
    ErrorException [ 4096 ]: Argument 3 passed to Fuel\Core\Form::select() must be an array, null given, called in c:\\fuel\app\views\users\_form.php on line 68 and defined what am i doing wrong? Thanks.
  • $this->template->content = View::factory('users/create')->set('countries', Helper::countries(),false);
    
    Here you request the view "users/create", but that doesn't match the error:
    ErrorException [ 4096 ]: Argument 3 passed to Fuel\Core\Form::select() must be an array, null given, called in c:\\fuel\app\views\users\_form.php on line 68 and defined
    
    That talks about the view "users/_form". As the error and the requested view don't match it looks like this isn't the full picture yet...
  • you're right I was calling the wrong view :( thanks for pointing that out.
  • Am not front of the pc now .. I thinking I have a nested view ... create view is calling _form view. When calling the _form view from create view do I need to pass the variables to the _form view again?
  • you either have to pas the variables to your _form view from the render function in your users/create file or use set_global instead of set.
  • I can get the variable if i use $this->template->set_global('data', $data); but not using the method below:
    $this->template->content = View::factory('users/create')
                    ->set('var','xxxxxxx',FALSE);
    

    Just wondering why the above code doesn't work and also what's the best way of passing variables to the view when using the template_controller?

Howdy, Stranger!

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

In this Discussion