Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
I can't connect partial in theme
  • if i write in my controller
     $this->theme->set_partial('footer', 'public/_global/footer');


    that

    Warning!



    Fuel\Core\PhpErrorException [ Warning ]:
    Invalid argument supplied for foreach()



    COREPATH/classes/theme.php @ line 309



    304
    305        // pre-process all defined partials
    306        foreach ($this->partials as $key => $partials)
    307        {
    308            $output '';
    309            foreach ($partials as $index => $partial)
    310            {
    311                // render the partial
    312                $output .= $partial->render();
    313            }
    314

    where to find the error


  • I have a feeling your theme renders twice.

    Up until 1.7 the $this->partials array is used in render() to collect the rendered output, before it is returned. Which means that if you call render() a second time, $this->partials is no longer a multidimensional array.

    So go through your code and check why it renders the theme twice.
  • my contoller
    http://bin.fuelphp.com/~s8

    my base contoller

    http://bin.fuelphp.com/~s9

    code is very simle but does not work
  • You're returning the Theme instance as response, so you're relying on the __toString() method to auto render the instance on output.

    Which means you might have an index.php issue, due to the double call to $response->body() towards the end. If you're not using those macro's, comment out that block as it says in the comments, only leaving the $response->send(true) at the bottom.
  • worked just do not understand why
  • HarroHarro
    Accepted Answer
    if (strpos($response->body(), '{exec_time}') !== false or strpos($response->body(), '{mem_usage}') !== false)

    contains twice the call $response->body() which will return the response, cast to string. Since your response is a theme instance object, it's __toString() method is called to convert it to string, which calls the theme's render() method. So that is called twice too.

    This has been rewritten in development to make sure it's rendered only once. This fix will be part of 1.7.1

Howdy, Stranger!

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

In this Discussion