Question

I stuck at the point why my variable won't be found.

here is a picture of the error enter image description here

The problem is that i set my route and everything that need to be i think.

Her i got my bootstrap.php

Route::set('categorie', 'categorie/<item>', array('item' => '.*'))
        ->defaults(array(
            'controller' => 'categorie',
            'action' => 'index',
        ));

In my opinion its te right way to do the route.

Here you got my controller

<?php

defined('SYSPATH') or die('No direct script access.');

class Controller_Categorie extends Controller_Base_Main {

    public function action_index() {
          /* 
         * Hier maakt hij de content template aan van een bepaalde view
         * Ook worden hier de standaard views gezet 
         */
        $menuview = View::factory('menu');
        $categorietree = View::factory('categorietree');
        $footer = View::factory('footer');
        $this->template->menu = $menuview;
        $this->template->categorietree = $categorietree;
        $this->template->footer = $footer;
        /* 
         * Hier maak een een view aan waar ik 2 sql querys aan bind zodat de sql niet midden in de tekst hoeft
         */
        $view = View::factory('categorie')
                -> bind('categorieen', $cat)
                -> bind('categorie_artikelen', $cat_artikelen);

        /* 
         * categorieen sql uitvoeren
         */
        $cat = ORM::factory('categorie')
                ->select('categorie_naam', 'categorie_inhoud')
                ->where('categorie_id','=',':CategorieID')
                ->find_all();

        /* 
         * categorie_artikelen sql uitvoeren
         */
        $cat_artikelen = ORM::factory('categorie')
                ->select('A.artikel_naam','A.artikel_id')
                ->join(array('artikelen', 'A'), 'LEFT OUTER')->on('AC.artikel_id', '=', 'A.artikel_id')
                ->join(array('categorieen', 'C'), 'LEFT OUTER')->on('AC.categorie_id', '=', 'C.categorie_id')
                ->where('AC.categorie_id', '=', ':CategorieID')
                ->order_by('A.artikel_naam');

        $this->template->content = $view;
     }
}

Also here is my controller. I don't know what could be wrong with it.

Here is my model

<?php
class Model_Categorie extends ORM
{
    protected $_table_name = 'categorieen';
    protected $_primary_key = 'categorie_id';

    /*
     * Veld categorienaam
     * returns string
     */
    public function getNaam()
    {
        return $this->categorie_naam;
    }
    /*
     * Veld categorieinhoud
     * returns string
     */
    public function getInhoud()
    {
        return $this->categorie_inhoud;
    }
}

I hope this is also done the right way of writing it.

This is the view i use for the controller

<div style="   
    padding: 15px;
    background-color: white;
    border: 1px solid #EEE;
    ">
    <?php foreach($cat as $c): ?>
            <h1><?php echo $c['categorie_naam']; ?></h1>
            <p class="article"><?php echo nl2br($c['categorie_inhoud']); ?></p>
    <?php endforeach; ?>

    <table class="table table-condensed">
            <?php foreach($cat_artikelen as $s) : ?>
                    <?php $letter = strtoupper($s['artikel_naam'][0]); ?>

                    <?php if ($letter != $prev_row): ?>
                            <tr>
                                    <td><h4><b><?php echo $letter; ?></b></h4></td>
                            </tr>
                    <?php endif; ?>

                    <tr>
                            <td><a href="artikel.php?id=<?php echo $s['artikel_id']; ?>">
                            <i class="file-icon"></i> <?php echo $s['artikel_naam']; ?>
                            </a></td>
                    </tr>
                    <?php $prev_row = $letter; ?>
            <?php endforeach; ?>
    </table>
</div>

I hope someone can help me out, I really stuck at this point.

Was it helpful?

Solution

In your controller you need to move $view assignment below the $cat.

/* 
 * categorieen sql uitvoeren
 */
$cat = ORM::factory('categorie')
           ->select('categorie_naam', 'categorie_inhoud')
           ->where('categorie_id','=',':CategorieID')
           ->find_all();

$view = View::factory('categorie')
           ->bind('categorieen', $cat)
           ->bind('categorie_artikelen', $cat_artikelen);

You are setting the variable as $categorieen so in your view you would need to update the foreach to the following:

<?php foreach($categorieen as $c): ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top