Welcome Guest, Not a member yet? Register   Sign In
text helper - loaded, but character_limiter not working
#1

[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:
Code:
function Blog() {
        parent::Controller();
        
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->helper('text');
        
        $this->load->scaffolding('entries');
    }

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

Code:
<?php foreach($query->result() as $row): ?>
        <h2>&lt;?=$row->title?&gt;</h2>
        <p>&lt;?=$row->character_limiter(body, 10);?&gt;</p>
        <p>&lt;?=anchor('blog/comments/'.$row->id, 'Comments');?&gt;</p>
        <hr>
    &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:
Code:
<p>&lt;?=$row->character_limiter(body, 10);?&gt;</p>

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

Edit:

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

Code:
&lt;?php
    $body_text = $row->body;
    print character_limiter($body_text, 210);
?&gt;
#2

[eluser]missionsix[/eluser]
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.

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

[eluser]Brad Morse[/eluser]
Perfect!

Thank you!

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

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

Thanks again!




Theme © iAndrew 2016 - Forum software by © MyBB