Problem with eval() in MY_string_helper

edited October 2011 in Bug Reports
I have been lot of hours trying to solve this problem and this is what I founded:
* I have an articles_model (like the one of the tutorial of WidgiCorp)

* In a controller I do:
$posts = fuel_model('articles', array('find' => 'all', 'where' => array('id'=>$id,'published'=>'yes'),'limit' => 1, 'order' => 'date_added desc'));

* in the custom view to show the article I do:
echo $post->content;

This was working excelent but... it started crashing with an article:

A PHP Error was encountered
Severity: Warning
Message: Please contact support about failure
Filename: helpers/MY_string_helper.php
Line Number: 58

I checked that in that line the code of the helper do:
$str = eval('?>'.$str.'<?php ');

So I Googled lot of hours about php's eval(), the fuel's helper, etc.
But couldn't solve it.
I thought it must be a "strange character" because the text was from a "copy paste" action.

I deleted every strange character but the problem was still there.
I started cropping the text and after a lot of time I founded that it fails because in a paragraph it had the word
"evaluate" !!!

To temporarily solve this I made a quick fix in the MY_string_helper (like your xml fix):
$str = str_replace('eval', 'e@val', $str);
the eval()
and then
$str = str_replace('e@val', 'eval', $str);

And that made it work fine for that particular article.

But I noticed that it worked fine in the "Fuel Blog module" if I typed the word "evaluate" in a post.
So I copied the blog's post content_formatted method to my model but it still crashes.

Do you know a better way to solve this?

Thank you!

Comments

  • edited 9:11PM
    I'll try and replicate the issue locally to see if I can see what may be going on.
  • edited 9:11PM
    Can you send me the text saved in the database that is getting served up for the content (or at least the smallest portion that is causing the problem). Am having trouble replicating the issue locally.
  • edited 9:11PM
    The smallest portion is just the word "eval". In the Fuel CMS module it saves to database ok but the problem happens when you try to get it in a view to the "end user".

    If you can't replicate it may be a server's issue (!?) mmmm...

    Here I copy my files code:
    * the cms module is the one of your example for "articles_model"

    * the call to get the article is:
    myserver.com/myfolder/index.php/getNota/index/1
    (the number 1 is the article's id)

    * The controller called in getNota.php (extends CI_Controller):
    function index($id = null){
    $vars['id']=$id;
    $this->load->library('session');
    $posts = fuel_model('articles',array('find' => 'all','where' => array('id'=>$id,'published'=>'yes'),'limit' => 1, 'order' => 'date_added desc'));
    $vars['posts']=$posts;
    $page_init = array('location' => 'getNota');
    $this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init);
    $this->fuel_page->add_variables($vars);
    $this->fuel_page->render();
    }

    * the view getNota.php called:
    <?php fuel_set_var('layout', 'ipad'); ?>

    <?php foreach($posts as $post) : ?>

    <?php echo $post->title; ?>

    <?php echo $post->permalink; ?>

    <?php echo $post->content_formatted; ?>
    <?php endforeach; ?>


    (I Added the method "get_content_formatted" in the Article_model to see if it solves the problem but it was the same as using the "content" attribute alone )
Sign In or Register to comment.