Support the ongoing development of Laravel.io →
posted 9 years ago
Blade
Last updated 2 years ago.
0

you have $description[3] missing.

hence the loop fails as it's trying to find an index that isn't there.

took me a while to work out!

j.

0

Yeah i tried that.. But that's not working.. when i fix that, and refresh the page it just keeps saying:

Whoops, looks like something went wrong.

0

apps/routes.php

Route::get('/test', 'TestController@test');

app/controllers/TestController.php


class TestController extends BaseController {

    public function test()
    {
		
        $description[0] = 'This is a description for picture number 1 inside this slider and you can use <strong>HTML Tags</strong> inside too.';
        $description[1] = 'This is a description for picture number 2 inside this slider and you can use <em>HTML Tags</em> inside too.';
        $description[2] = 'This is a description for picture number 3 inside this slider and you can use <u>HTML Tags</u> inside too.';
        $description[3] = 'This is a description for picture number 4 inside this slider and you can use <a href="#">HTML Tags</a> inside too.';
        $description[4] = 'This is a description for picture number 5 inside this slider and you can use <u>HTML Tags</u> inside too.';
        $description[5] = 'This is a description for picture number 6 inside this slider and you can use <u>HTML Tags</u> inside too.';
        $description[6] = 'This is a description for picture number 7 inside this slider and you can use <u>HTML Tags</u> inside too.';
        $description[7] = 'This is a description for picture number 8 inside this slider and you can use <u>HTML Tags</u> inside too.';
		
        // either method works
        //$data = array('description'=>$description);
        //return View::make('test')->with($data);
		
         return View::make('test')->with('description',$description);

	}
}

app/views/test.blade.php

@for ($x = 0; $x < count($description); $x++)
<p>
x={{$x}}:
{{ $description[$x] }}
</p>
@endfor
Last updated 9 years ago.
0

The count works, because it's showing x = number as an output.. But as soon as i add $description[$x] it gives the error again.. but when i change it to $description[5] for example, it works..

0

set debug=1 in /app/config/app.php

0

i'm guessing your imagesTotal is 9

you've got <= in your code, try < instead

(it's a 0 index so it goes from eg 0..8 not 1..9)

Last updated 9 years ago.
0

you can check in log error file looking for error in view or controller.

0

Try using

@foreach ($description as $desc)
    {{ $desc }}
@endforeach
Last updated 9 years ago.
0

So, when i turn on the debug it shows:

Undefined offset: 8

When i change the <= to <, it shows them all, but i only want to show the description that is with the number of the photo..

The foreach also shows them all..

0

When i change the <= to <, it shows them all, but i only want to show the description that is with the number of the photo..

The foreach also shows them all..

Please specify what you are trying to accomplish. The loop is doing what you told it to do; the initial error you reported was because of the invalid offset which was a result of using <= instead of <

The way the loop is structured it will output the corresponding description to the value of $x. Since arrays are zero based your first picture description is $description[0]. $x is also going to be 0 not 1. If you want to specify the picture number accurately then use another variable. For instance if you pass $i with the other variables in your controller and set it to 1 you could do the following.

@for($x = 0; $x < $imagesTotal; $x++)
    <p>
    {{ $i++ }}
    {{ $description[$x] }}</p>
@endfor
Last updated 9 years ago.
0

The thing i'm trying to do is:

I have a photo gallery, and i want the description of the photo selected below the photo.. The images are being shown by:

<div class="galleryPreviewImage"> <?php for ($i = 1; $i <= $imagesTotal; $i++) { echo '<img class="previewImage' . $i . '" src="../images/instal' . $i . '.jpg" width="400" height="auto" alt="" />'; } ?> </div>

P.S., how can i do that code block thingy? I tried [code][/code], but it doesnt work

Last updated 9 years ago.
0

StefanSchols said: P.S., how can i do that code block thingy? I tried [code][/code], but it doesnt work

http://laravel.io/forum/01-31-2014-how-to-mark-up-forum-posts

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.