CodeIgniter Forums
CodeIgniter from another class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: CodeIgniter from another class (/showthread.php?tid=29078)



CodeIgniter from another class - El Forum - 03-29-2010

[eluser]consigliere[/eluser]
I am writing my own class project in PHP and I would like to import form validation class from codeIgniter, is this possible?


CodeIgniter from another class - El Forum - 03-29-2010

[eluser]nelson.wells[/eluser]
Yes. In your functions in your class, you will do $ci =& get_instance(); and then you can access the super object like you would any other time (usually like 'this').

$ci->load->library("form_validation");


CodeIgniter from another class - El Forum - 03-29-2010

[eluser]consigliere[/eluser]
[quote author="nelson.wells" date="1269920188"]Yes. In your functions in your class, you will do $ci =& get_instance(); and then you can access the super object like you would any other time (usually like 'this').

$ci->load->library("form_validation");[/quote]

I watched something like this in http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html

What codeIgniter libraries do I need to import on my own class?

thanks


CodeIgniter from another class - El Forum - 03-29-2010

[eluser]frist44[/eluser]
depends what kind of functionality you need. If you explain more about what you're trying to do inside your class, we could probably give you more direction.


CodeIgniter from another class - El Forum - 03-30-2010

[eluser]consigliere[/eluser]
[quote author="frist44" date="1269931582"]depends what kind of functionality you need. If you explain more about what you're trying to do inside your class, we could probably give you more direction.[/quote]

My case would be Calling CI libraries from outside script instead of http://codeigniter.com/wiki/Calling_CI_models_from_outside_script/,

I want to use form validation class from a AMFPHP Service.

:o)


CodeIgniter from another class - El Forum - 03-31-2010

[eluser]consigliere[/eluser]
Any help?

:o)


CodeIgniter from another class - El Forum - 03-31-2010

[eluser]consigliere[/eluser]
I tried and PHP throws this error:
Quote:Fatal error: Call to a member function library() on a non-object in Vehicles.php on line

Here are my files based on http://codeigniter.com/wiki/Calling_CI_models_from_outside_script/

config_constants.php
Code:
<?php

if( ! $system_folder)
    $system_folder = "system";

if( ! $application_folder)
    $application_folder = "application";

if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
{
    $system_folder = str_replace("\\", "/", realpath(dirname(__FILE__))).'/'.$system_folder;
}


define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION));
define('FCPATH', __FILE__);
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('BASEPATH', $system_folder.'/');

if (is_dir($application_folder))
{
    define('APPPATH', $application_folder.'/');
}
else
{
    if ($application_folder == '')
    {
        $application_folder = 'application';
    }

    define('APPPATH', BASEPATH.$application_folder.'/');
}

if ( ! defined('E_STRICT'))
{
    define('E_STRICT', 2048);
}

?>

ci_model_remote_open.php
Code:
<?php

require_once('config_constants.php');

require(BASEPATH.'codeigniter/Common'.EXT);

set_error_handler('_exception_handler');
set_magic_quotes_runtime(0); // Kill magic quotes

$CFG     =& load_class('Config');
$LANG    =& load_class('Language');

if (floor(phpversion()) < 5)
{
    load_class('Loader', FALSE);
    require(BASEPATH.'codeigniter/Base4'.EXT);
}
else
{
    require(BASEPATH.'codeigniter/Base5'.EXT);
}

// instantiate a "fake" controller
$CI = load_class('Controller');

require_once(BASEPATH.'libraries/Form_validation'.EXT);

?&gt;

Vehicles.php
Code:
&lt;?php

class Vehicles
{
    function __construct()
    {
        require_once("deca/utils/CodeIgniter_1.7.2/ci_model_remote_open.php");
        require_once("deca/utils/CodeIgniter_1.7.2/system/libraries/Form_validation.php");      
    }
    
    function sendCommands($param) {
        if (isset($_SESSION['USER_PWD'])) {
                        
            // CodeIgniter Code
            $system_folder = "CodeIgniter/system";
            $CI->load->library('form_validation');
            
            if ($CI->form_validation->run() == FALSE)
            {
                return "ERROR";
            }
            else
            {
                return "TRUE";
            }            
            
    }
        
    function __destruct()
    {
      $this->DB->close();
    }
}

?&gt;



CodeIgniter from another class - El Forum - 04-05-2010

[eluser]consigliere[/eluser]
HELP!!!