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?

1
  • I dont see $vesti_slider anywhere.....are you sure you dont mean to do foreach($vst['slider'] as $vst)? Commented Jun 18, 2013 at 15:47

1 Answer 1

4

You need to pass data to a view as an array (or object), with the key becoming the variable name.

<?php foreach ($vesti_slider as $vst): ?>
    <?php $this->load->view('templates/admin/vesti', array('vst' => $vst)) ?>
<?php endforeach ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.