CodeIgniter Forums
Post sheet - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Post sheet (/showthread.php?tid=519)



Post sheet - juninhodeluca - 12-13-2014

Hello guys,
I have an webapp which the user insert a specific sheet. Those sheets are predefined by the admin. So... some sheets have 15 lines, other ones have 50.
On submit, the user can to choose to SAVE or to SEND or to EXPORT or to PRINT the sheet.
But, if the user choice be SEND or EXPORT or PRINT, the sheet need to save itself first.

I am using something like that:

PHP Code:
Class Sheet {

 
   public function save() {
 
       // form validation run here
 
       // save in DB
 
   }

 
   public function send() {
 
       // form validation run here
 
       // save in DB
 
       // write the output file
 
   }




Of course I have a redundance in validating and saving the data into DB.

I tried to do something like that

PHP Code:
   public function send() {
 
       $this->save();
 
       //code to write
 
   

and also tried changing save to a static method

PHP Code:
   public function send() {
 
       self::save()
 
       // code to write
 
   


None work.
Some suggestion?


RE: Post sheet - InsiteFX - 12-13-2014

If your using a class library then you need to access external methods using the CI Super Object.

Code:
class yourClass
{
    private $_ci;

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

        $this->_ci = get_instance();
    }
}

// access db and models using $this->_ci->db->get() etc;



RE: Post sheet - Rufnex - 12-13-2014

It it is your own class, you have to load it first. Did you do that?


RE: Post sheet - Narf - 12-14-2014

(12-13-2014, 06:59 AM)InsiteFX Wrote: If your using a class library then you need to access external methods using the CI Super Object.


Code:
class yourClass
{
   private $_ci;

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

       $this->_ci = get_instance();
   }
}

// access db and models using $this->_ci->db->get() etc;

This code will trigger a fatal error. There's no 'parent' to call when you don't extend anything.