By: Keith
Date: 2010-10-03
Time: 19:00
|
Problems with TBS + phpAR
I'm just beginning with TBS, and I am using it in integration with phpActiveRecord to create a basic forum system.
I'm getting the following error:
`TinyButStrong Error when merging block [ForumList]: invalid query 'categories[0]->forums' because global variable 'categories' is not found.`
Category.php:
<?php
class Category extends ActiveRecord\Model {
static $has_many = array(
array('forums')
);
function index() {
$categories = Category::all(array('order' => 'sortno ASC'));
$GLOBALS['body']->LoadTemplate('templates/categories/index.tpl');
$GLOBALS['body']->MergeBlock('CatList', $categories);
$GLOBALS['body']->MergeBlock('ForumList', 'array', 'categories[%p1%]->forums');
}
}
?> |
Forum.php:
<?php
class Forum extends ActiveRecord\Model {
static $belongs_to = array(
array('category')
);
}
?> |
index.tpl:
<br />
<table width=100% border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="btl"></td>
<td class="btop">[CatList.name;block=table;bmagnet=table]</td>
<td class="btr"></td>
</tr>
<tr>
<td class="bleft"></td>
<td style="text-align: center;">
<table width="100%">
<tr>
<td style="width: 50px; text-align: center; vertical-align: middle;"><div class="img_forum_left"></div></td>
<td>[ForumList.id][ForumList.name;block=tr;bmagnet=tr;p1=[CatList.$]]</td>
<td style="width: 80px;">0 Topics</td>
<td style="width: 80px;">0 Replies</td>
<td style="width: 250px;">Last Post: 10-03-2010 11:05 AM<br />By: <a href="#">Keith</a><br />In: <a href="#">Test Topic</a></td>
</tr>
</table>
</td>
<td class="bright"></td>
</tr>
<tr>
<td class="bbl"></td>
<td class="bbottom"></td>
<td class="bbr"></td>
</tr>
</table>
<br /> |
If anyone can point me in the right direction I'd be grateful :D
|
By: Keith
Date: 2010-10-03
Time: 19:28
|
Re: Problems with TBS + phpAR
New Category.php:
<?php
class Category extends ActiveRecord\Model {
static $has_many = array(
array('forums')
);
function index() {
$GLOBALS['categories'] = Category::all(array('order' => 'sortno ASC'));
$GLOBALS['body']->LoadTemplate('templates/categories/index.tpl');
$GLOBALS['body']->MergeBlock('CatList', $GLOBALS['categories']);
$GLOBALS['body']->MergeBlock('ForumList', 'array', 'categories[%p1%]->forums');
}
}
?> |
Got it to stop showing the error, however I don't think it is passing the forum list...
It shows nothing, no errors, but no data.
However in PHP with this code, I can see the name of each forum under category 1:
foreach ($GLOBALS['categories'] as $cat) {
foreach ($cat->forums as $forum) {
echo $forum->name;
}
} |
|
By: Skrol29
Date: 2010-10-03
Time: 22:14
|
Re: Problems with TBS + phpAR
Hi Keith,
I can't see in your code the line where you ask to display the result.
Since you don't call $GLOBALS['body']->Show(), the merged content is stored only in $GLOBALS['body']->Source
|
By: Keith
Date: 2010-10-04
Time: 01:03
|
Re: Problems with TBS + phpAR
I apologize, there is an index page that calls everything. The show was at the bottom of the page. Do not have the code anymore, I dropped it and started doing it by scratch =/
If you are interested, this is the current outline (it has been modified to no longer use TBS - will likely modify it tomorrow to put TBS back in):
<?php
require_once 'includes/init.php';
include('templates/' . STYLE_PATH . '/header.php');
#Get ?p= and break it up (?p=module:page)
list($module, $page) = explode(":", $_GET['p']);
if ($module == "") {
$model = "Category";
} else {
$module = explode("_", $module);
foreach ($module as $word) {
$model .= ucwords($word);
}
#Wait.... Is our model even valid?
if(!file_exists("models/$model.php")) {
System::noperm();
}
}
#If we have a module but no page, make page index
if ($model != "" && $page == "") {
$page = "index";
}
if ($_GET['id'] != "" and is_numeric($_GET['id'])) {
$parse_id = $_GET['id'];
}
if(file_exists("models/$model.php")) {
try {
$model::$page($parse_id);
} catch (Exception $error) {
System::noperm(); #Fail gracefully for the user
}
}
include('templates/' . STYLE_PATH . '/footer.php');
?> |
|
|
Posting in progress.
Please wait...
|