Welcome Guest, Not a member yet? Register   Sign In
unable to locate model
#1

i have the code working just fine on my mac but as soon as i upload it to pagoda box it cant find one of the models. The model filename is listmodel.php, the class name is Listmodel and im loading Listmodel.

listmodel.php
Code:
<?php if (!defined('BASEPATH')) exit('No direct script allowed');
session_start();
Class Listmodel extends CI_Model
{
    function createList($name)
    {
        $user = $this->session->userdata('logged_in');

        $this->db->set('userId', $user['id']);
        $this->db->set('name', $name);

        $this->db->insert('lists');

        return $this->db->insert_id();
    }

    function addItem($listId, $name, $url)
    {
        $this->db->set('listId', $listId);
        $this->db->set('name', $name);
        $this->db->set('url', $url);

        $this->db->insert('listItem');

        return $listId;
    }

    function getListById($id)
    {
        $this->db->select('name, userId');
        $this->db->from('lists');
        $this->db->where('id', $id);

        $query = $this->db->get();
        if($query->num_rows() == 0) return false;

        $return = array();
        $result = $query->result();
        foreach($result as $row)
        {
            $return['name'] = $row->name;
            $return['userId'] = $row->userId;
        }

        $this->db->select('id, name, url, bought');
        $this->db->from('listItems');
        $this->db->where('listId', $id);

        $query = $this->db->get();
        $items = array();
        $result = $query->result();
        foreach($result as $row)
        {
            $item['id'] = $row->id;
            $item['name'] = $row->name;
            $item['url'] = $row->url;
            $item['bought'] = $row->bought;

            $items[] = $item;
        }
        $return['items'] = $items;

        return $return;
    }

    function getListsbyEmail($email)
    {
        $this->db->select('lists.id, lists.name');
        $this->db->from('lists');
        $this->db->join('users', 'users.id = lists.userId');
        $this->db->where('users.email', $email);

        $query = $this->db->get();
        return $query->result_array();
    }
}

loading model
Code:
<?php if (!defined('BASEPATH')) exit('No direct script allowed');

Class Lists extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('Listmodel', '', TRUE);
    }

error
Code:
An Error Was Encountered

Unable to locate the model you have specified: listmodel

I get
Code:
Forbidden

You don't have permission to access /application/models/listmodel.php on this server.
when trying to access the file directly.

dont know what else to try anymore. the file is there. Again, it works locally on my mac but when i upload it breaks. i have other models in the same folder that work just fine on the server.
Reply
#2

(This post was last modified: 11-16-2014, 12:06 AM by Rufnex.)

try to name your model "List_model" and load the model like this

Code:
$this->load->model('list_model');

Reply
#3

File and class name should start with capital letter so..
Code:
Listmodel.php
class Listmodel {}

after that

Code:
$this->load->model('listmodel');
$this->listmodel->blabla...
Best VPS Hosting : Digital Ocean
Reply
#4

(11-15-2014, 06:48 PM)bia.morton Wrote: i have the code working just fine on my mac but as soon as i upload it to pagoda box it cant find one of the models. The model filename is listmodel.php, the class name is Listmodel and im loading Listmodel.

listmodel.php

Code:
<?php if (!defined('BASEPATH')) exit('No direct script allowed');
session_start();
Class Listmodel extends CI_Model
{
    function createList($name)
    {
        $user = $this->session->userdata('logged_in');

        $this->db->set('userId', $user['id']);
        $this->db->set('name', $name);

        $this->db->insert('lists');

        return $this->db->insert_id();
    }

    function addItem($listId, $name, $url)
    {
        $this->db->set('listId', $listId);
        $this->db->set('name', $name);
        $this->db->set('url', $url);

        $this->db->insert('listItem');

        return $listId;
    }

    function getListById($id)
    {
        $this->db->select('name, userId');
        $this->db->from('lists');
        $this->db->where('id', $id);

        $query = $this->db->get();
        if($query->num_rows() == 0) return false;

        $return = array();
        $result = $query->result();
        foreach($result as $row)
        {
            $return['name'] = $row->name;
            $return['userId'] = $row->userId;
        }

        $this->db->select('id, name, url, bought');
        $this->db->from('listItems');
        $this->db->where('listId', $id);

        $query = $this->db->get();
        $items = array();
        $result = $query->result();
        foreach($result as $row)
        {
            $item['id'] = $row->id;
            $item['name'] = $row->name;
            $item['url'] = $row->url;
            $item['bought'] = $row->bought;

            $items[] = $item;
        }
        $return['items'] = $items;

        return $return;
    }

    function getListsbyEmail($email)
    {
        $this->db->select('lists.id, lists.name');
        $this->db->from('lists');
        $this->db->join('users', 'users.id = lists.userId');
        $this->db->where('users.email', $email);

        $query = $this->db->get();
        return $query->result_array();
    }
}

loading model

Code:
<?php if (!defined('BASEPATH')) exit('No direct script allowed');

Class Lists extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('Listmodel', '', TRUE);
    }

error

Code:
An Error Was Encountered

Unable to locate the model you have specified: listmodel

I get

Code:
Forbidden

You don't have permission to access /application/models/listmodel.php on this server.
when trying to access the file directly.

dont know what else to try anymore. the file is there. Again, it works locally on my mac but when i upload it breaks. i have other models in the same folder that work just fine on the server.

Did you really defined the class with "Class"? or is that a problem with the forum's editor? if not, try to replace in your code "Class" with "class".
Reply




Theme © iAndrew 2016 - Forum software by © MyBB