简体   繁体   中英

Is it possible to get the index of foreach in view in codeigniter?

I am doing the CMS, I would like to place the images in different position(I did not use the foreach because the positioning of foreach its either vertical or horizontal). For example i have 4-5 images(So the index will start at 0 until 3/4), the first image/index(which is 0) I would like to place it in the top left, the second image/index(which is 1) I would like to place it in the bottom right etc etc.. Is it possible? If yes how?

Note: I am converting my laravel project into codeigniter, that's why my codes in my view is in the laravel View

<div class="fh5co-explore">
            <div class="container">
                <div class="row">
                    <div class="col-md-8 col-md-pull-1 animate-box">
                        @if($content[0]['status']=="Activated")
                        <img class="img-resposive" src="assets/images/{{$content[0]['img_jumbotron']}}" alt="work">
                        @endif
                    </div>
                    <div class="col-md-4 animate-box">
                        <div class="mt">
                           <div>
                               <?php ?>      
                                <h4><i class="icon-user"></i>{{$textcontent['0']['text_header'] }} ?></h4>
                                <p>{{{ $text[0]['text_description']}}}</p>
                            </div>
                            <div>
                                <h4><i class="icon-video2"></i>{{ $text[1]['text_header'] }}</h4>
                                <p>{{{ $text[1]['text_description']}}}</p>
                            </div>
                            <div>
                                    <h4><i class="icon-shield"></i>{{ $text[2]['text_header'] }}</h4>
                                    <p>{{{ $text[1]['text_description']}}}</p>
                                </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

I think laravel have default template engine so you can free to use the format what you mentioned in your code.But in codeigniter there no any default template engines.But there an alternate way to use the same method in codeigniter by using Template Parser Class .To enable this you must include the library call parser, include this in your codeigniter current controller,

$this->load->library('parser');

For more information please refer this documentation,

https://www.codeigniter.com/userguide3/libraries/parser.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM