Question: Use findAll function that report errors,as follows:
Notice: Trying to get property of non-object in D:\Xampp\xampplite\htdocs\betsite\lib\AkActiveRecord.php on line 2482
Notice: Trying to get property of non-object in D:\Xampp\xampplite\htdocs\betsite\lib\AkActiveRecord.php on line 2484
Notice: Trying to get property of non-object in D:\Xampp\xampplite\htdocs\betsite\lib\AkActiveRecord.php on line 2486
Fatal error: Cannot use object of type Bettype as array in D:\Xampp\xampplite\htdocs\betsite\app\helpers\home_helper.php on line 7
File Source:
class HomeController extends ApplicationController
{
var $layout = 'page';
var $appTitle = null;
var $models = 'bettype';
function index ()
{
$this->appTitle = 'Home::index';
$this->bettypes = $this->Bettype->findAll();
}
}
class HomeHelper
{
function bettype($bettypes)
{
for($i=0;$i<count($bettypes);$i++){
$string .= "<li><a href='#'><span>".$bettypes[$i]->title."</span></a></li>";
}
return $string;
}
}
Template file quote:
<?php echo $home_helper->bettype($bettypes);?>
Who help me please?
Thank you very much!
Make sure that
$this->Bettypes =& $this->Bettype->findAll();
return records from BD and check it at your helper before looping
class HomeHelper
{
function bettype($Bettypes)
{
if (!empty($Bettypes)) {
$output = '';
foreach (array_keys($Bettypes) as $k) {
$output .= '<li><a href="#">'.$Bettypes[$k]->get('title').'</a></li>';
}
}
return !empty($output) ? $output : '';
}
}
Try at your controller a debug of Bettytypes
function index ()
{
$this->appTitle = 'Home::index';
$this->Bettype->dbug(); //SQL debug
$this->Bettypes =& $this->Bettype->findAll();
Ak::debug($this->Bettypes);
}
1 to 2 of 2