Welcome Guest, Not a member yet? Register   Sign In
Call to a member function getResult() on bool error in Code igniter 4
#1

I'm following the tutorial on the official Code Igniter 4 website, and I'm running into the error "Call to a member function getResult() on bool". It seems to be springing up from my use of the findAll() method. Here is my mode, NewsModel.php:
PHP Code:
<?php 

namespace App\Models;

use 
CodeIgniter\Model;

class 
NewsModel extends Model 
{
    protected $table 'news';

    public function getNews($slug false)
    {
        if ($slug === false)
        {
            return $this->findAll();
        }

        return $this->where(['slug' => $slug])->first();
    }

Here is m controller, News.php
PHP Code:
<?php 

namespace App\Controllers;

class 
News extends BaseController 
{
    /**
    * View all news articles
    */
    public function index()
    {
        // load the model
        $model model(NewsModel::class);

        // set up the data array
        $data = [
            'news'  => $model->getNews(),
            'title' => 'News archive',
        ];

        // return the views to the user
        return view('templates/header'$data)
            view('news/overview')
            view('templates/footer');
    }

    /**
    * View a specific news article
    */
    public function view($slug null)
    {
        $model model(NewsModel::class);

        // get the news data for the specific news item
        $data['news'] = $model->getNews($slug);

        // if nothing was found then throw an error
        if (empty($data['news']))
        {
            throw new \CodeIgniter\Exceptions\PageNotFoundException('Cannot find news item: ' $slug);
        }

        $data['title'] = $data['news']['title'];

        return view('templates/header'$data)
            view('news/view_news')
            view('templates/footer');

    }

Reply
#2

You can see the Error Page if you set development mode.
See
- https://codeigniter4.github.io/CodeIgnit...rror-pages
- https://codeigniter4.github.io/CodeIgnit...pment-mode
Reply




Theme © iAndrew 2016 - Forum software by © MyBB