我坚持为什么找不到我的变量。
这是错误的图片
问题是我设定了路线以及我认为需要做的所有事情。
她我得到了我的 bootstrap.php
Route::set('categorie', 'categorie/<item>', array('item' => '.*'))
->defaults(array(
'controller' => 'categorie',
'action' => 'index',
));
我认为这是正确的方法。
在这里你有我的 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;
}
}
这也是我的控制器。我不知道这可能是什么问题。
这是我的 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;
}
}
我希望这也是正确的编写方式。
这是view
我用的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>
我希望有人能帮助我,我真的坚持了这一点。
在您的控制器中,您需要将$view
分配移到下方$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);
您正在设置变量,$categorieen
因此在您的视图中需要将foreach更新为以下内容:
<?php foreach($categorieen as $c): ?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句