dongzhimin2231 2014-01-17 08:14
浏览 32
已采纳

为什么kohana找不到我的变量

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.

  • 写回答

1条回答 默认 最新

  • dongnai5905 2014-01-17 09:57
    关注

    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): ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀