Welcome Guest, Not a member yet? Register   Sign In
not reaching the Model
#1

[eluser]dinisptc[/eluser]
this is the controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {


    function Welcome() {
        parent::Controller();

        /* check if users is logged in */

        
        /* set template */
        //$this->template->set_template('backoffice');

        /* enable profiling */
        //$this->output->enable_profiler($this->config->item('debug'));
    }



    public function index()
    {
        $data=array();
        /**** page data ****/
        $data['controller']='welcome';
            
                //the error is in this line
        $data['tipos']=$this->tipos_model->find_all(1);
        
        $this->load->helper('url');
        //$config['base_url'] = site_url("/welcome/index/");
        $this->load->view('header',$data);
        $this->load->view('conteudos_empresa');
        $this->load->view('footer');
        
        
    }
}

this is the model

Code:
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Tipos_model extends Model {

    function Tipos_model() {
        // Call the Model constructor
        parent::Model();
    }


    function find_all($tipo_activo=null) {

        echo 'activo'.$tipo_activo;
    
        if (isset($tipo_activo)) {
            $where = array('tipo_activo' => $tipo_activo);
            $this->db->where($where);
        }

        $query = $this->db->get('tipos');

        if ($query->num_rows() > 0) {
            foreach ($query->result_array() as $row) {
                $result[] = $row;
            }
        } else {
            $result = false;
        }
        return $result;
    }

~


the error

Erro HTTP 500.0 - Internal Server Error
Não é possível apresentar a página porque ocorreu um erro interno do servidor.
#2

[eluser]JonoB[/eluser]
You need to load the model before you can use it. Also make sure that you are using the constructor properly

http://ellislab.com/codeigniter/user-gui...odels.html
#3

[eluser]danmontgomery[/eluser]
Code:
function Welcome() {
        parent::Controller();

parent::Controller() doesn't exist, and you should really be using the __construct() syntax:

Code:
class Welcome extends CI_Controller {

    function __construct() {
        parent::__construct();
    }
}

Models need to extend CI_Model, not Model:

Code:
class Tipos_model extends CI_Model {

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

And, like JonoB said, you need to load the model before you can use it.

Code:
$this->load->model('tipos_model');
#4

[eluser]dinisptc[/eluser]
thanks

its working now




Theme © iAndrew 2016 - Forum software by © MyBB