find_all_by in new version not working?

edited November 2013 in Bug Reports
I recently updated my fuel 1.0 installation in an existing site to the latest version and had to update my php version to 5.4.19. Here is an existing script in one of my models:
$this->load->module_model(FUEL_FOLDER, 'fuel_relationships_model'); $this->load->model('scratch_images_model'); $related = $this->fuel_relationships_model->find_all_by_candidate_table_and_candidate_key('image_themes', $themeid); foreach ($related as $item) { $img_id = $item->foreign_key; $images[] = $this->scratch_images_model->find_one_by_id($img_id); }When I do a debug_query I get this:
SELECT prizes.* FROM (`client_games`) JOIN `prizes_to_client_games` ON `prizes_to_client_games`.`game_id` = `client_games`.`id` JOIN `prizes` ON `prizes`.`id`=`prizes_to_client_games`.`prize_id` WHERE `prizes_to_client_games`.`game_id` = '1' ORDER BY `win_odds` desc, `id` asc
When I paste that into phpMyAdmin I get a recordset of 6 items. But, when I try to iterate over the items like this:
foreach ( $images as $img ) { // do stuff }
I get a NULL set.
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: images

Any idea what might be going on here? I'm stumped.

Comments

  • edited 5:18PM
    I'd first initialize the $images variable before doing $images[] above the foreach loop.
    $images = array(); Then I'd check to see if $this->scratch_images_model->find_one_by_id($img_id); returns any value.
  • edited 5:18PM
    Thanks. One of the things that was a little confusing was that it seemed I could no longer pass variables from the controller to the rendered view as uri segments like this:
    $this->fuel->pages->render('sweepstakes_game/$seg2/$seg3', $vars);
    Doing it that way was taking me to a 404 page not found.

    When I just go ahead and add the 2 variables to the $vars array like this it works$vars['client_id'] = $seg2; $vars['client_game_permalink'] = $seg3; $this->fuel->pages->render('sweepstakes_game', $vars);
  • edited 5:18PM
    It could be because you need to set it up so that that page is recognized as being able to have segments passed to it. In your MY_fuel.php file, you can do something like the following which will allow 2 segments to be passed to the page sweepstakes_game:
    $config['max_page_params'] = array('sweepstakes_game' => 2);
  • edited 5:18PM
    ahhhh! I did not know that config item was there. Duh. Thanks so much. I guess in my previous versions of Fuel CMS it defaulted to 2 or 3.
Sign In or Register to comment.