Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7162439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:44:07+00:00 2026-05-28T13:44:07+00:00

For reference, please visit this page here . When trying to get a view

  • 0

For reference, please visit this page here. When trying to get a view display on one particular model, I am getting an undefined index error. Specifically, any data from my Coupon model. Here is my controller code:

public function seafood() {

$this->paginate['Restaurant']=array(
        'limit'=>9,
        'order' => 'RAND()',
        'contain'=>array(
                'User'=>array(
                    'id', 'user_name'),

                'Coupon'=>array(
                    'id','description','expires','end_date','promo_code','restaurant_id')
                    ),
        'conditions'=>array(

                'Restaurant.active'=>1,
                'Restaurant.seafood'=>'Seafood'
                )   
    );
$data = $this->paginate('Restaurant');
$this->set('seafood', $data);

when I debug($seafood) in my view, all data for Coupon shows, so I know it is correctly pulling data and associating it with my Restaurant model. However, when I create a foreach loop with my $seafood array, I get nothing but undefined index errors for anything Coupon-related. What’s weird is that I also have my controller pulling from the User model and anything I call up from that model in the view gets rendered. Here is my view code:

 <?php foreach ($seafood as $res) { ?>
        .....irrelevant code.....
 <p><?php if($res['Coupon']['description'] !=''){
        echo $this->Text->truncate($res['Coupon']['description'], 200, array('ending'=>'...', 'exact'=>false) );
        }
        else echo 'Sorry, a description of this restaurant\'s promotion is not available.  <br><br><br>';
         ?><a href="<?php echo $res['Restaurant']['website']; ?>"><em> (read more -->)</em></a></p>
    <br />
    <div>
    <a href="<?php echo $res['Restaurant']['website']; ?>" id="specials"><span style="margin-left:36px;">Promo Code:&nbsp;&nbsp;<span style="font-style:bold; color:#FF0000;"><?php echo $res['User']['user_name']; ?></span></span></a>
    <a href=" " id="print"><span style="margin-left:24px;">Print</span></a>
<?php } ?>
   ......more irrelevant code.....

I have tried removing the containable behavior from the array but the results are the same. I should point out that when the debug array prints, it goes in order: Restaurant, User, Coupon. Is cake somehow losing the Coupon array because it is 3rd? Or is my view code just screwy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:44:08+00:00Added an answer on May 28, 2026 at 1:44 pm

    Looks like Restaurant hasMany Coupon so Coupon is an indexed array. You’ll need a nested for loop.

    foreach ($seafood as $res) {
        //irrelevant
        foreach ($res['Coupon'] as $coupon) {
            if($coupon['description'] !=''){
                //do stuff
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody please explain what does this warning mean: undefined reference to 'WinMain@16' ?
Please reference the this example : I'm trying to create vertical dividers between my
please can anybody explain this code from C++ Reference site : #include <iostream> #include
Can someone please translate this into English? The primary reference Microsoft.SQLServer.ManagedDTS, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91,
I'm new to C# web development. Please bear with me. I'm trying to reference
Please check this bellow program. ::Program:: <?php $xml=' &lt;books&gt; &lt;book&gt; &lt;name&gt;Java complete reference&lt;/name&gt; &lt;cost&gt;256&lt;/cost&gt;
In reference to this answer to a Stack Overflow question : what is bench-testing
I reference the current page in a class with Page page = HttpContext.Current.CurrentHandler as
I have this page that displays pictures in a div. I have jquery cycle
Can someone please provide links to any paper/reference that talks about disconnected components in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.