Viewed   167 times

I have class MY_Controller extends CI_Controller and common logic for big profile section, so I'va tried to create class Profile extends MY_Controller with common logic for profile section and all class related to this section should extends this Profile class as I understand right, but when I tried to create class Index extends Profile I recieve an error:

Fatal error: Class 'Profile' not found

CodeIgniter tries to find this class in index.php which I am running.

Where is my mistake? Or maybe there is anoter better way to mark out common logic?

 Answers

4

I take it you have put your MY_Controller in /application/core, and set the prefix in the config. I would be careful about using index as a class name though. As a function/method in Codeigniter it has a dedicated behaviour.

If you then want to extend that controller you need to put the classes in the same file.

E.g. In /application core

/* start of php file */
class MY_Controller extends CI_Controller {
    public function __construct() {
       parent::__construct();
    }
...
}

class another_controller extends MY_Controller {
    public function __construct() {
       parent::__construct();
    }
...
}
/* end of php file */

In /application/controllers

class foo extends MY_Controller {
    public function __construct() {
       parent::__construct();
    }
...
}

or

class bar extends another_controller {
    public function __construct() {
       parent::__construct();
    }
...
}
Friday, September 16, 2022
4

Why not extend the controllers so the login method is within a MY controller (within the core folder of your application) and all your other controllers extend this. For example you could have:

class MY_Controller extends CI_Controller {
    public function is_logged()
    {
        //Your code here
    }
}

and your main controllers could then extend this as follows:

class Home_Controller extends MY_Controller {
    public function show_home()
    {
         if (!$this->is_logged()) {
           return false;
         }
    }
}

For further information visit: Creating Core System Classes

New link is here: https://www.codeigniter.com/user_guide/general/core_classes.html?highlight=core%20classes

Sunday, December 11, 2022
 
thmschk
 
1

better to pass the value in the hidden field

<form class="addinvestmentform" action="<?php echo base_url();?>index.php/ctl_dbcont/input_investment" name="application" method="post" >
<input type="hidden" name="my_id" value="<?php echo $id; ?>"/>
</form>

in your ci function

function input_investment() {
    $id = $this->input->post('my_id');
    $this->load->helper('form');
    $this->load->helper('html');
    $this->load->model('mod_user');
    $this->mod_user->insertinvestment($id);
}

or if you want (A test)

// Sample view

<?php $id = 1; ?>
<form action="<?php echo base_url('my_class/my_method/' . $id); ?>" method="post" >
  <input type="submit" />
</form>

// Controller

class My_class extends CI_Controller {

  public function index() {
    $this->load->view('my_class');
  }

  public function my_method($id) {
    echo $id; // outputs 1
  }

}
Thursday, September 29, 2022
 
2

I think all you need to do is (for example):

 $append_events = get_event_info($day, $month, $year);
 $array['dates']['1']['event'] = $append_events['events'];

Then you can access your elements:

 $array['dates']['1']['event'][$id]['title']    
 $array['dates']['1']['event'][$id]['description']    
Thursday, October 27, 2022
 
5

I think the problem is with short tags,

<?php include 'header.php';?>

But i would say, in codeigniter use,

$this->load->view("header.php");
Wednesday, October 5, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :