PageRenderTime 29ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/example/controllers/example_controller.php

https://bitbucket.org/wanwizard/modular-ci/
PHP | 101 lines | 69 code | 23 blank | 9 comment | 2 complexity | c8affece0c3b1ad7785c659cb317ed3e MD5 | raw file
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. class Example_controller extends Admin_Controller
  3. {
  4. function __construct()
  5. {
  6. parent::__construct();
  7. $this->load->library('form_validation');
  8. ob_start();
  9. var_dump(func_get_args());
  10. $dump = ob_get_clean();
  11. $this->output->append_output(
  12. "Controller constructor parameters:<br />".$dump
  13. );
  14. $this->output->append_output(
  15. "Example controller constructed.<br /><br />"
  16. );
  17. }
  18. // to test the default index method
  19. function index()
  20. {
  21. ob_start();
  22. var_dump(func_get_args());
  23. $dump = ob_get_clean();
  24. $this->output->append_output(
  25. "Welcome from the module 'Example', controller 'example_controller', method index!<br />".$dump
  26. );
  27. }
  28. // to test a named method
  29. function example()
  30. {
  31. $this->output->append_output(
  32. "Welcome from the module 'Example', controller 'example_controller', method example!<br />"
  33. );
  34. // check how we need to load our modules classes
  35. // this depends on the module configuration
  36. $thisclass = $this->__modulereference;
  37. $this->output->append_output( '<h3>Calling: Test controller</h3>' );
  38. $this->$thisclass->controller->test_controller->example();
  39. ob_start();
  40. var_dump(func_get_args());
  41. $dump = ob_get_clean();
  42. $this->output->append_output(
  43. "Welcome from the module 'Example', controller 'example_controller', method example!<br />".$dump
  44. );
  45. // Load a module config file
  46. $this->output->append_output( '<h3>Calling: $this->example->config(\'example\');</h3>' );
  47. $loaded = $this->$thisclass->config('example_config', TRUE);
  48. if ( $loaded )
  49. {
  50. ob_start();
  51. // if you use sections, configs are stored in the config array
  52. // using the 'modulename/configfilename' key, to make them unique
  53. var_dump($this->config->config['example/example_config']);
  54. $dump = ob_get_clean();
  55. $this->output->append_output(
  56. "Config loaded:<br />".$dump
  57. );
  58. }
  59. // load a view from our module
  60. $this->output->append_output( '<h3>Calling: $this->'.$thisclass.'->model->example_model->example(); from inside the example module controller</h3>' );
  61. $this->$thisclass->model->example_model->example();
  62. $this->output->append_output( '<h3>Calling: $this->'.$thisclass.'->view(\'example\'); from inside the example module controller</h3>' );
  63. $this->$thisclass->view('example');
  64. // dynamic module language support
  65. $this->output->append_output( '<h3>Dynamic Language support, calling: $this->'.$thisclass.'->lang("dynamic")->line("example"); from inside the example module controller</h3>' );
  66. ob_start();
  67. var_dump($this->$thisclass->lang('dynamic')->line('example'));
  68. $dump = ob_get_clean();
  69. $this->output->append_output(
  70. "Language string returned:<br />".$dump
  71. );
  72. $this->output->append_output( '<h3>Calling: echo $this->'.$thisclass.'->library->example_library->example; from inside the example controller</h3>' );
  73. $this->output->append_output( $this->$thisclass->library->example_library->example('x') . '<br/>' );
  74. $this->output->append_output( '<h3>Calling: echo $this->'.$thisclass.'->model->example_model->example; from inside the example controller</h3>' );
  75. $this->output->append_output( $this->$thisclass->model->example_model->example('y') . '<br/>' );
  76. return 'Controller return value';
  77. }
  78. }