Welcome Guest, Not a member yet? Register   Sign In
Trouble implementing a new controller in an existing project.
#4

[eluser]jedd[/eluser]
[quote author="henryboy" date="1248916782"]
Code:
class Testing extends Controller {

    function index() {
                parent::Controller();
        echo 'Hello World';
    }
}
[/quote]

I'm not sure why you think the parent::Controller() line should exist in the index() rather than the class's constructor. I suspect you've made some changes from the other controllers without understanding about how constructors work ... ? This is a PHP thing rather than a CI thing, so I'd suggest you read up on the PHP manual about classes/constructors.

You want something like this, btw:
Code:
<?php
class Testing extends Controller {

        function Testing()
        {
             parent::Controller();
        }

        function index()
        {
             echo "Hello sailor";
        }
}


Quote:Not sure what you mean by changing the other line if using PHP-4 safe mode constructors.

With PHP4 (something that CI goes to some effort to maintain compatibility with) you have a constructor that shares the same name (see above) but with PHP5 you can use __construct() - the biggest advantage of this is that you do not have to change your class name in two places whenever you use an existing one as the basis of a new one.


Messages In This Thread
Trouble implementing a new controller in an existing project. - by El Forum - 07-29-2009, 02:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB