Illegal offset warning
Permalink
Working on Crud from Cookbook - Chapter 6 - interface for dashboard -
Can't seem to get edit working I get a Illegal offset warning and headers already sent. Can't figure it out - here is edit function
public function edit($id) {
Loader::model('blog_post');
$post = new BlogPost();
$post->load('id = ?', $id);
$this->set($post, (array) $post);
}
Being called from a list of items in database
<div class="ccm-ui">
<div class="ccm-pane">
<?php
$dashboard = Loader::helper('concrete/dashboard');
echo $dashboard->getDashboardPaneHeader('Blog Posts');
?>
<div class="ccm-pane-body ccm-pane-footer">
<a href="<?php echo $this->url('/dashboard/posts/add/') ?>" class="btn pull-right"> New Item</a>
<table class="table table-striped table-bordered">
<tr>
<th>ID</th>
<th>Title</th>
<th>Post Date</th>
<th>Actions</th>
</tr>
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post->id ?></td>
<td><?php echo $post->title ?></td>
<td><?php echo date('F j, Y g:i a', strtotime($post->post_date)) ?></td>
<td>
<a href="<?php echo $this->url('dashboard/posts/add/edit/', $post->id) ?>" class="btn">Edit</a>
<a href="<?php echo $this->action('delete', $post->id) ?>" class="btn danger">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div
The URL looks right when I click the button - the actual error is -
Warning: Illegal offset type in /Applications/MAMP/htdocs/INTCommunications/C5/concrete5.6.1.2/concrete/core/libraries/controller.php on line 323
Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/INTCommunications/C5/concrete5.6.1.2/concrete/core/libraries/controller.php:322) in /Applications/MAMP/htdocs/INTCommunications/C5/concrete5.6.1.2/concrete/core/libraries/view.php on line 917
Not sure what the problem is - help is appreciated
Can't seem to get edit working I get a Illegal offset warning and headers already sent. Can't figure it out - here is edit function
public function edit($id) {
Loader::model('blog_post');
$post = new BlogPost();
$post->load('id = ?', $id);
$this->set($post, (array) $post);
}
Being called from a list of items in database
<div class="ccm-ui">
<div class="ccm-pane">
<?php
$dashboard = Loader::helper('concrete/dashboard');
echo $dashboard->getDashboardPaneHeader('Blog Posts');
?>
<div class="ccm-pane-body ccm-pane-footer">
<a href="<?php echo $this->url('/dashboard/posts/add/') ?>" class="btn pull-right"> New Item</a>
<table class="table table-striped table-bordered">
<tr>
<th>ID</th>
<th>Title</th>
<th>Post Date</th>
<th>Actions</th>
</tr>
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post->id ?></td>
<td><?php echo $post->title ?></td>
<td><?php echo date('F j, Y g:i a', strtotime($post->post_date)) ?></td>
<td>
<a href="<?php echo $this->url('dashboard/posts/add/edit/', $post->id) ?>" class="btn">Edit</a>
<a href="<?php echo $this->action('delete', $post->id) ?>" class="btn danger">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</div
The URL looks right when I click the button - the actual error is -
Warning: Illegal offset type in /Applications/MAMP/htdocs/INTCommunications/C5/concrete5.6.1.2/concrete/core/libraries/controller.php on line 323
Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/INTCommunications/C5/concrete5.6.1.2/concrete/core/libraries/controller.php:322) in /Applications/MAMP/htdocs/INTCommunications/C5/concrete5.6.1.2/concrete/core/libraries/view.php on line 917
Not sure what the problem is - help is appreciated
Thanks jero- that fixed it. pretty big mistake to leave in a book especially in the downloaded code which could easily be updated.
Oh and thank you for the explanation - just fixing was not my only intention for posting here. Seeing why it happened is why and I thank you for that.
You're trying to use an object ($post) as an array index (core/libraries/controller.php line 323) which is why you're getting an illegal offset warning. The headers sent warning occurs because you triggered the first warning.