1

I have this template file:

<article class="box vest p10">
    <h2 class="box_naslov"><?php echo $vst['naslov'] ?></h2>
    <p><?php echo word_limiter($vst['opis'], 25) ?></p>
    <a href="<?php echo base_url('admin/vesti/update/' . $vst['id_clanak']) ?>">Izmeni Vest</a>
    <a role=obrisi href="<?php echo base_url('admin/vesti_delete/' . $vst['id_clanak']) ?>">Obriši Vest</a>

    <?php
        $slider = $vst['slider'] == 0 ? 'Ubaci u slider'  : 'Izbaci iz slider-a';
        $q = $vst['slider'] == 0 ? 'ubaci'  : 'izbaci';
     ?>
    <a role=slider  href="<?php echo base_url('admin/vesti_slider/' . $vst['id_clanak'] . '?q=' . $q )?>"><?php echo $slider ?></a>
</article>

In my view file I have tried this:

<?php foreach ($vesti_slider as $vst): ?>
    <?php $this->load->view('templates/admin/vesti', $vst) ?>
<?php endforeach ?>

I got error - ** Undefined variable: vst**. Is there some way to do this?

4

1 回答 1

4

您需要将数据作为数组(或对象)传递给视图,键成为变量名。

<?php foreach ($vesti_slider as $vst): ?>
    <?php $this->load->view('templates/admin/vesti', array('vst' => $vst)) ?>
<?php endforeach ?>
于 2013-06-18T15:47:08.960 回答