• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how often will public function __construct() run?

#1
In the top of my controller i have 

public function __construct()

In it I initialize the database, load helpers and libs, get environment variables, and then runs $this->_init(). It seems that _construct (and thus _init) is running multiple times. In init() I initialize fusionAuth. Thus I am doing it multiple times per user. I have have seen this through use of the debugger. For example, every time new method in the controller is called. 

Is this correct? where should I be initializing "system wide" resources?
proof that an old dog can learn new tricks
Reply

#2
I believe the constructor is called once in a request.
Reply

#3
Thanks. In that case, where should I place "run-once" type activities, such as opening databases and loading session variables? BTW, I am getting up to the point where I am going to need to fully test my application and have never set up testing before. Now I know there are different types of testing (over 20 different kinds). What type of testing does your book address? Also, I am having trouble with Composer. Does that preclude using your testing procedure?
proof that an old dog can learn new tricks
Reply

#4
PHP is shared nothing architecture.
There is no "run-once" type activities.

> What type of testing does your book address?

My book explains how to write PHPUnit test code, and
Codeception acceptance testing for CodeIgniter 3.x.

> I am having trouble with Composer. Does that preclude using your testing procedure?

I don't know. But the book is not about Composer.

And the book is a bit out of dated. You can learn testing
concepts and basic knowledge, but you will need to refer
to the manual of each tool to build the latest development
environment.

Software in the book:
• PHP 5.5 (You can use PHP 5.4 or 5.6)
• CodeIgniter 3.0
• ci-phpunit-test 0.10
• PHPUnit 4.8
• Codeception 2.1
• Selenium Standalone Server 2.48
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.