CodeIgniter Forums
log page views in database where? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: log page views in database where? (/showthread.php?tid=2875)



log page views in database where? - El Forum - 08-29-2007

[eluser]matt2012[/eluser]
I want to create a simple stats component that logs the page and subpage
of every page view along with some other stuff basically I want to run a
simple database insert of $this->uri->segment(1) etc. where is the best place
to run the code in the construct function of every controller or is this a use of a hook?

or has someone written a plugin or library for this ?


log page views in database where? - El Forum - 08-29-2007

[eluser]xwero[/eluser]
You could extend the controller

Code:
class MY_Controller extends Controller
{
   function MY_Controller()
    {
       parent::Controller();
       $url = $this->uri->uri_string();
       // database insert
    }

}

And every controller you create should insert an url in your database.

I saw somewhere on the forum you should extend the normal controllers from the MY_Controller class but i think that is not necessary because the extended class functionality should be loaded instead of the parent class. Or am i wrong about this?