[eluser]reaktivo[/eluser]
[quote author="Rey Philip Regis" date="1228362098"][quote author="xwero" date="1228325282"]Controllers are not extended like other classes. The MY_Controller file only provides you a way to 'autoload' extended controllers.
The extended controllers are only known to the controller that is called by the url when you extend it with a extended controller class.
Code:
// MY_Controller.php
class Extend1 extends Controller {}
class Extend2 extends Controller {}
// user.php
class User extends Controller {} // child of the controller class
// members.php
class Members extends Extend1 {} // grandchild of the controller class
[/quote]
Didn't know this yet..But at least I know now..What's the use of creating a new controller when you can extend it in you application? What do you thing reactivo trying to do? Just curious....[/quote]
I really don't know if this is the best way of doing this task but...
I was looking for a way to remove form submission validation on Controllers, and allow all Controllers to validate different forms, for example a user auth form submitted and displayed on different view's loaded on different Controllers. You would not want to check for user authentication on each controller. So I added some code to the Controller constructor to load and call a model method, here it is:
Code:
if($service = $this->input->post('service')) {
$this->load->library('Request');
list($model, $method) = explode(".", $service);
$this->load->model($model);
$this->response = $this->$model->$method($_POST);
if($this->request->is_ajax()) {
switch($this->input->post('format')) {
case 'php':
serialize($this->response);
break;
case 'xml':
//convert to xml
break;
case 'json':
default:
json_encode($this->response);
break;
}
}
}
This removes the need for my Form to be tied to a Controller, also, it allows to make ajax request without the complete page being returned. And since in CI 1.7 I can have form_validation on the model itself, I think is nice.
I you feel you have a better way of doing this, please let me know! Thanks.