Concrete5 Cookbook - Don't understand logic in code

Permalink
Hello,
I am fairly new to Concrete5 but I have been building websites for 15 years. Most of my database stuff in the past I have coded in Coldfusion and have switched to PHP in just the last year. Anyway last week I purchased the book Concrete5 Cookbook. Read through it and then started to go step by step through tutorial chapters.

First one I tried I received errors - loaded up the code from the book download code and the errors were still there. Posted it here and someone pointed out the problem right away ( something was not quoted that should have been quoted - probably just an oversight). Excellent!
But now I have tried the blueprint chapter to build a fully functional Event Calendar Block - went through it step by step - great no errors but - As I was going through it I couldn't see where the logic was in the block. i.e. the block has a form that asks how many events to show ( item_limit) when you add the block- but there is nowhere where this logic is implemented. In other words regardless of what number you add when using the block they all show up on the page. This oversight is not mentioned in the book or the downloaded code. There is a few lines at the end of the chapter regarding things that you could add - i.e. Hiding events where the date has passed ( Would of kind of like to have seen that also ) but no mention that the limit doesn't work.

Has anyone else tried this block code?- I emailed the author David Strack about the first error and haven't heard back from him.

I believe that there should be some kind of logic that ties the btCookbookevent table to the block view on the foreach loop. Not sure where that logic would be inputted. Any ideas?

the add.php and edit.php has an include to a form.php where the enduser inputs the limit for events
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$form = Loader::helper('form');
?>
<div class="ccm-ui">
<table class="table table-striped table-bordered">
<tr>
<td>
<?php echo t('Maximum events to show') ?>
</td>
<td>
<?php echo $form->text('item_limit', $item_limit) ?>
</td>
</tr>
</table>

then in the view.php
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<h1 class="events-title"><?php echo t('Events Calendar') ?></h1>
<div class="events-list">
<?php if (!empty($events)): ?>
<?php foreach ($events as $event): ?>
<div class="event-item">
<h2><?php echo $event->title ?></h2>
<div class="event-date">
<?php echo $event->getDate() ?>
<?php if ($event->location): ?>

and so on
Any help would really help me understand to learn and I will in the future ( when I feel I have a good grasp ) reciprocate.

Jim Robinson

INTcommunications
 
Remo replied on at Permalink Reply
Remo
The block tables gets tied to view.php (and add.php, edit.php) by specifying its name in the block controller.

Can you zip the whole folder you've got and attach it to this discussion? I should be able to point you in the right direction pretty quickly.
INTcommunications replied on at Permalink Reply 1 Attachment
INTcommunications
Hi, was a little reluctant to attach file because it is from a book but I have found errors in other chapters and still have not heard from the author. The book does lay it out pretty well ( step by step with explanation ) but as I stated above I am trying to learn and if something is left out - It makes it very confusing - I have come across this in the past but usually the author will forget to put something in the book that is in the code, In this case I can't see the code in either. See Attached zip of the add-on
Remo replied on at Permalink Reply
Remo
I think you're right, there's a missing piece.

I hardly ever use ActiveRecord but if you open controller.php in the block, you can use this:

$events = $e->find('1=1 ORDER BY event_date LIMIT ' . intval($this->item_limit));


maybe there's an official parameter for that limit or even an additional method, but the code above does work as well..
INTcommunications replied on at Permalink Reply
INTcommunications
Thanks Remo- I''ll give that a shot. You say that you hardly ever use that (active record ) . How do you get extra information when someone inputs a block? In this case when the end user inputs the number - it is being entered into the database with the blockID. So when you come back you can edit the number - The view was not showing any change. Shouldn't the foreach loop in the view have the limit variable i.e. records <= variable. Don't quite know the syntax. Thanks again for your help
Remo replied on at Permalink Reply
Remo
No, that would be bad MVC design. The data should be prepared in the model/controller, the view is just supposed to print the data.

All discrete fields part of the table specified in the main table are automatically available in the view, edit, add files..