CodeIgniter Forums

Full Version: text helper - loaded, but character_limiter not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Brad Morse[/eluser]
I recently completed the two blog tutorials and wanted to add to it.

I loaded the text helper within the blog controller:
function Blog() {

Then I tried to put a limit on the body part of the blog post within the blog view:

<?php foreach($query->result() as $row): ?>
        <p>&lt;?=$row->character_limiter(body, 10);?&gt;</p>
        <p>&lt;?=anchor('blog/comments/'.$row->id, 'Comments');?&gt;</p>
    &lt;?php endforeach; ?&gt;

I receive this error;

Fatal error: Call to undefined function: character_limiter() in /path_to/ci_system/application/views/blog_view.php on line 11

Line 11 is:
<p>&lt;?=$row->character_limiter(body, 10);?&gt;</p>

I imagine this is a simple fix, any help is appreciated. Thank you.


I tried this and it seems to work, but is there a better way of writing this?

    $body_text = $row->body;
    print character_limiter($body_text, 210);

El Forum

Looks like you've figured out that helper functions are just functions and not methods attached to objects. With that said, you've done it correctly, but you shouldn't need to define a variable here.

<p>&lt;? echo character_limiter("$row->body", 10);?&gt;</p>

El Forum

[eluser]Brad Morse[/eluser]

Thank you!

I appreciate the help, I was completely off from my original attempt, here is my original attempt at doing this below:

<p>&lt;?=$row->character_limiter(body, 10);?&gt;</p>

Thanks again!