View Code Being Changed by FuelCMS

edited October 2014 in News & Announcements
I'm working in 1.2 for the first time, but know this was also in 1.06. I'm suspecting a model problem, but the model is extremely simple and works fine if I'm using it in Admin. I've also verified that the generated query syntax works (in phpMyAdmin) , and I can get a valid record count into my view -- but I can't loop through the records -- portions of the loop (and any anything else with logic in it) keeps being changed into html "comments" by fuelcms.

The error message:
7 A PHP Error was encountered Severity: Notice Message: Undefined variable: plant Filename: core/Loader.php(332) : eval()'d code Line Number: 57 NULL
The specific line is looking for short tags, but neither short nor long tags work and both get the same treatment

The controller code:
$where .= "((PlantScientific LIKE '%".$pname."%') OR (PlantCommon LIKE '%".$pname."%'))"; $vars['plants'] = $plnts = fuel_model('plants', array ('select'=>'PlantScientific, PlantCommon, PlantUnique','order'=>'PlantScientific','where'=>$where)); $vars ['plnt_count'] = count ($plnts); $this->fuel->pages->render('plants/plants', $vars);

The view code (anything in the loop fails)--
<?=$plnt_count?> <? foreach ($plants as $plant) { ?> <?=gettype($plant)?> <? } ?> The generated code (from show source) 7 <? foreach ($plants as $plant) {; ?> A PHP Error was encountered Severity: Notice Message: Undefined variable: plant Filename: core/Loader.php(332) : eval()'d code Line Number: 57 NULL <? }; ?> The "NULL" is coming from the gettype since $plant is never set. FuelCms is obviously changing the code into something that appears to be html (usually gets highlighted like a comment) Any ideas? Thanks.

Comments

  • edited 12:41PM
    Oops -- forgot the The model -- very basic
    require_once(FUEL_PATH.'models/base_module_model.php'); class Plants_model extends Base_module_model { function __construct() { parent::__construct('srd_plants'); } #Used in admin to display list for editing function list_items($limit = NULL, $offset = NULL, $col = 'PlantScientific', $order = 'asc') { $this->db->select('id, PlantScientific,PlantCommon', FALSE); $data = parent::list_items($limit, $offset, $col, $order); return $data; } function form_fields($values = array()) { $fields = parent::form_fields($values); return $fields; } } class Plant_model extends Base_module_record { }
  • edited 12:41PM
    If you do a print_obj() on $plant, what does it return? The print_obj() function is found in the utility helper and good for debugging database records because it prevents the infinite loop due to the CI references.

    Also if you just use fuel_model('plants') without the additional query parameters, do you have the same problem?

    Lastly, does this work?
    <?php foreach ($plants as $plant) : ?> <?=gettype($plant)?> <? endforeach; ?>
  • edited October 2014
    Hmmm ----

    Your comment sent me back to looking at long and short tags in both fuelcms configuration and php.ini, and that was the answer -- thanks.

    I had started with long tags and it did not work -- however, it seems to be working now with
    <?php foreach ($plants as $plant) : ?> <?=gettype($plant)?> <?php endforeach; ?>and I'm guessing, that I also forgot to make the closing tag a long one.

    The entire range of errors that I've gotten would suggest that there may be an issue with
    the fuelcms configuration setting
    $config['rewrite_short_tags'] = TRUE; (short tags are off in my php.ini).
  • edited October 2014
    That configuration is part of CI and it looks like the code doesn't rewrite <? tags, just <?= tags
    https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Loader.php
Sign In or Register to comment.