Welcome Guest, Not a member yet? Register   Sign In
Using a library class
#1

[eluser]Ikkaku-Sama[/eluser]
Hi!

I'm trying to create a file called GeneralModel.php, because my models have the same functions and I want to put them into one file to my Models extend this GeneralModel. I tried to put it at this folder: system/application/models, but it wasn't right. I read the CodeIgniter Tutorial and now I'm putting my GeneralModel.php at the libraries folder. But, when I tried to extend GeneralModel, generated this error:

Fatal error: Class 'GeneralModel' not found in C:\wamp\www\myProject\system\application\models\programasModel.php on line 2

I loaded my GeneralModel at the autoload.php and now appears this error:

Fatal error: Class 'Model' not found in C:\wamp\www\myProject\system\application\libraries\GeneralModel.php on line 2

My General insn't finding my the class Model. How can I solve this? Is it right what I'm doing?
#2

[eluser]Kepler[/eluser]
Did you code GeneralModel as:

Code:
class GeneralModel extends Model {

    /**
     * Constructor
     *
     * @access public
     */
    function GeneralModel()
    {
        log_message('debug', "GeneralModel Class Initialized");
    }
...
}

And ProgramasModel.php as:

Code:
<?php

class ProgramasModel extends GeneralModel {

And set autoload.php as:

Code:
$autoload['libraries'] = array(...,'generalmodel');

I tried it and it works for me.
#3

[eluser]Johan André[/eluser]
Use MY_Model.php in libraries folder instead. It's for extending models.

MY_Model.php
Code:
class MY_Model extends Model
{
    function MY_Model()
    {
        parent::Model();
    }

    function available_to_all_models()
    {
        echo "Hooray!";
    }
}

Then let your models extend MY_Model instead of Model.
#4

[eluser]Ikkaku-Sama[/eluser]
[quote author="Johan André" date="1247636222"]Use MY_Model.php in libraries folder instead. It's for extending models.

MY_Model.php
Code:
class MY_Model extends Model
{
    function MY_Model()
    {
        parent::Model();
    }

    function available_to_all_models()
    {
        echo "Hooray!";
    }
}

Then let your models extend MY_Model instead of Model.[/quote]

Thank you, Johan André. Your solution solved my problem.




Theme © iAndrew 2016 - Forum software by © MyBB