Welcome Guest, Not a member yet? Register   Sign In
Calling Model Function
#1

I am very new to CI4 and while I'm getting on well converting the basics of my script based app to CI4, I am strugling with database calls.



From the documentation I believe I configure parameters in my model, and then create functions that utilise these parameters? Something Like this.


PHP Code:
<?php namespace App\Models\Admin;

use 
CodeIgniter\Model;

class 
Admin_nav extends Model {
    
protected 
$table      'event_master';
    protected $primaryKey 'id';

    protected $returnType 'array';
    
    function 
admin_links () {
        
$admin_links $this->orderBy('event_from_date''desc')
                   ->findAll();
    }
    
    function 
score_links ($id) {
        
$score_links $this->where('event_id'$id)
                   ->findAll();
    }



and then call a function from the controller, something like this

PHP Code:
<?php namespace App\Controllers\Admin;

class 
Admin_nav extends BaseController
{
    public function 
index()
    {
        
$event_links model('Admin\Admin_nav');
    
        
$data['links']=$event_links->admin_links();        
        
        
        echo 
view('templates/admin_nav_test',$data);
    }





But am geeting an error "Call to a member function admin_links() on null" which I do not understand?

Please tell me I'm on the right track???
Reply


Messages In This Thread
Calling Model Function - by 68thorby68 - 04-28-2020, 06:45 AM
RE: Calling Model Function - by kilishan - 04-28-2020, 07:02 AM
RE: Calling Model Function - by InsiteFX - 04-28-2020, 08:08 AM
RE: Calling Model Function - by jreklund - 04-28-2020, 09:53 AM
RE: Calling Model Function - by 68thorby68 - 04-29-2020, 01:57 AM
RE: Calling Model Function - by jreklund - 04-29-2020, 10:55 AM
RE: Calling Model Function - by 68thorby68 - 04-30-2020, 04:13 AM
RE: Calling Model Function - by jreklund - 05-01-2020, 09:03 AM
RE: Calling Model Function - by 68thorby68 - 05-03-2020, 02:22 AM
RE: Calling Model Function - by jreklund - 05-03-2020, 03:01 AM
RE: Calling Model Function - by 68thorby68 - 05-03-2020, 03:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB