Welcome Guest, Not a member yet? Register   Sign In
Trouble with view_cell
#1

(This post was last modified: 05-05-2021, 07:26 AM by Zeff.)

Hi folks,
I tried to use the view_cell() function in a view file, but I always get an error: 
Code:
TypeError

Return value of CodeIgniter\View\Cell::render() must be of the type string, null returned
My view file is very simple, I just inserted a view_cell() in the default CI welcome_message.php:
Code:
<div class="heroe">
    <h1>Welcome to CodeIgniter <?= CodeIgniter\CodeIgniter::CI_VERSION ?></h1>
    <h2>The small framework with powerful features</h2>
</div>
</header>

<!-- CONTENT -->

<?=view_cell('\App\Controllers\TestController::bar')?>

<section>
    <h1>About this page</h1>

The TestController.php (which has no constructor!) has a simple method:

Code:
public function bar()
{
    echo 'BAR';
}
I use no params, so it's a very simple test but I keep on getting this error!

Many thanks for the golden tip! [Image: wink.png]

Attached Files Thumbnail(s)
   
Reply
#2

echo returns nothing.
Your method must return a string.

return 'BAR'; instead of echo 'BAR';
Reply
#3

Hello iRedds,
Thanks so much for your hint, it worked by returning a string. I was so used to echo views from the previous tutorials I followed and I missed this perticular difference...
You made my day!
Smile

Zeff
Reply




Theme © iAndrew 2016 - Forum software by © MyBB