Welcome Guest, Not a member yet? Register   Sign In
Problems with custom controllers
#1

[eluser]Unknown[/eluser]
Hello.
Been planning to code an ACL-supported controller and is honestly quite perplexed.
I have two controllers for testing purposes when I tried extending the default CI controller.
First one:
/application/libraries/MY_Controller.php
Code:
<?php
class MY_Controller extends Controller {
    function MY_Controller() {
        parent::Controller();
    }
}
Second one:
/application/libraries/MY_Testcontroller.php
Code:
<?php
class MY_Testcontroller extends Controller {
    function MY_Testcontroller() {
        parent::Controller();
    }
}

First one works, second one doesn't. Now, can anyone explain why in gods name I can't name my CUSTOM controllers any name I want (accepting the fact that I have to have the prefix MY_ in the front)?
There are naming conventions for the file, the class itself when it comes to capitalization, but why the same name as the original class I am trying to extend?

If this is a gotcha, I am a bit tempted to jump ship in fear of what other gotchas I am to expect.

//Frank
#2

[eluser]InsiteFX[/eluser]
Hi,

You can name anythibg you want in code but the filename has to be MY_Controller.
When you do this the your Constructor would be the name you used like below.

Code:
class MY_Testcontroller extends Controller {
    function MY_Testcontroller() {
        parent::MY_Controller();
    }
}

Enjoy
InsiteFX
#3

[eluser]Unknown[/eluser]
Thanks but that was not really what I was looking for. The name "MY_Testcontroller" was merely there for demonstrating that anything other than "MY_Controller" doesn't seem to work. I started out with just "ACL_Controller" which ofcourse failed.

Code:
class Testar extends MY_Testcontroller {
    
    function Testar() {
        parent::MY_Testcontroller();
    }
    
    function index() {
        echo "hello";
    }
}
This is what I tried to do, but doesn't really work.
#4

[eluser]John_Betong[/eluser]
I have just tried this on my LOCALHOST and it seems to work.
 
 
Code:
// ./controller/c_test.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

require APPPATH .'libraries/MY_test.php';

//============================================
class C_test extends MY_test
{
    
   //===============================================================================================
   function index($owner=NULL, $pagename=NULL, $key=NULL)
   {
     echo 'THIS WORKS FINE ON MY LOCALHOST';
   }

}//endclass

// ./libararies/MY_test.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

// http://ellislab.com/forums/viewthread/62859/
class My_test extends Controller
{
    
    // ESSENTIAL TO HAVE A CONTRUCT
        // http://ellislab.com/forums/viewthread/128180/
      function __construct()
    {
      parent::__construct();
      $this->load->helper('url');
    }    


  //==================================================
  function index()
  {
    // this is NEVER EVER called      
    echo __FILE__; die;
  }//endfunc

//endclass
 
 
I reckon that it would be beneficial if CodeIgniter elaborated a little on their help and maybe with the installation supplied some empty classes, models, plugins, etc.
 
 
 
 




Theme © iAndrew 2016 - Forum software by © MyBB