Welcome Guest, Not a member yet? Register   Sign In
back to basics
#1

(This post was last modified: 11-13-2021, 01:14 PM by richb201.)

Whenever I try to go to a new function in my controller, index() reruns. In index() I am calling $this->report_generator_amazing() which displays my dashboard. Could this be the reason I can't seem to display anything but the dashboard? I don't think it worked this way when I was using my local apache, but I could be wrong. Besides showing my dashboard, there is a function call in index() that downloads some images from s3. I really only want to do this once. 

So, can someone tell me, does _init() run every time I go to a new method in my controller? I am just getting confused.....

How can I get index not to run EVERY time?
proof that an old dog can learn new tricks
Reply
#2

Post your controller and your routes' configuration. There's no reason index() would be called for every routes but only the one configured to call index().
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

(This post was last modified: 11-16-2021, 04:02 AM by richb201.)

(11-15-2021, 03:17 PM)includebeer Wrote: Post your controller and your routes' configuration. There's no reason index() would be called for every routes but only the one configured to call index().

Here is routes.php:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

$route['default_controller'] = 'Configure';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['registration'] = 'registration';
$route['login'] = 'login';
$route['subit_backend']['GET']='subit_backend/register'
and here is config.php:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
$config['base_url'] = 'http://staging.researchstudyonline.com:8181/';
$config['index_page'] = 'index.php';    //only for ubuntu
$config['uri_protocol'] = 'PATH_INFO';        // 5/20/20
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = TRUE;
$config['subclass_prefix'] = 'MY_';
$config['composer_autoload'] = FCPATH 'vendor/autoload.php';    //for ubuntu
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
$config['enable_query_strings'] = TRUE;
$config['access_token'] = '#';
$config['allow_get_array'] = TRUE;
$config['log_threshold'] = 4;
$config['log_path'] = '';
$config['log_file_extension'] = '';
$config['log_file_permissions'] = 0644;
$config['log_date_format'] = 'Y-m-d H:i:s';

$config['error_views_path'] = '';
$config['cache_path'] = '';
$config['cache_query_string'] = FALSE;
$config['encryption_key'] = '';
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'cisession';
$config['sess_expiration'] = 28800;  // this is 8 hours, every 8 hours the session will be destroyed and when it does the user will be logged off
have any activity in 30 minutesthey will log off via javascript_funcs.js
$config
['sess_save_path'] = APPPATH.'cache';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
$config['standardize_newlines'] = FALSE;
$config['global_xss_filtering'] = FALSE;
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
$config['compress_output'] = FALSE;
$config['time_reference'] = 'local';
$config['rewrite_short_tags'] = FALSE;
$config['proxy_ips'] = ''
And here is the top of the controller, Configure.php:

PHP Code:
class Configure extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->helper(array('form''url''file''array','download','directory'));
        $this->load->library('grocery_CRUD');
        $this->load->library('email');
        $this->load->library('image_lib');
        $this->load->library('image_CRUD');
        $this->load->library('ftp');
        $this->load->library('form_validation');
        $this->load->helper('cookie''download');
        $this->load->model('MyModel');
        $this->load->js("/js/javascript_funcs.js");
        $this->_init();
    }


    private function _init()
    {
        $this->output->enable_profiler(FALSE);  //turn on profiler
        //this sets all the credentials into session
        $this->session->set_userdata('LOCAL'getenv('LOCAL'));
        $this->session->set_userdata('AWS_ACCESS_KEY_ID'getenv('AWS_ACCESS_KEY_ID'));
        $this->session->set_userdata('AWS_SECRET_ACCESS_KEY'getenv('AWS_SECRET_ACCESS_KEY'));
        $this->session->set_userdata('hostname'getenv('hostname'));
        $this->session->set_userdata('username'getenv('username'));
        $this->session->set_userdata('password'getenv('password'));
        $this->session->set_userdata('connectionString'getenv('connectionString'));
        $this->session->set_userdata('key'getenv('key'));
        $this->session->set_userdata('secret'getenv('secret'));
        $this->session->set_userdata('onetime'0);
        $_SESSION['apiKey'] = getenv('apiKey');
        $_SESSION['applicationID_survey'] = getenv('applicationID_survey');
        $_SESSION['applicationID_login'] = getenv('applicationID_login');
        $_SESSION['applicationID_admin_login'] = getenv('applicationID_admin_login');
        $_SESSION['applicationID_admin_register_login'] = getenv('applicationID_admin_register_login');  //this is for both register and login
        $_SESSION['emailTemplate'] = getenv('emailTemplate');
        $_SESSION['tenantID_survey'] = getenv('tenantID_survey');
        $_SESSION['client'] = new FusionAuth\FusionAuthClient($_SESSION['apiKey'], "http://fusionauth:9011");
        //sendpulse section
        $_SESSION['sendpulse_API_USER_ID'] = getenv('sendpulseID');
        $_SESSION['sendpulse_SECRET'] = getenv('sendpulseSecret');
        $_SESSION['stripe_SECRET'] = getenv('stripe_secret_key');
$_SESSION['sendpulse_SECRET'], new FileStorage());
        $this->session->set_userdata('iTransfered',0);
        $this->db->where('email'$this->session->userdata('userid'));
        $this->db->where('company_division'$this->session->userdata('campaign'));
        $query $this->db->get('campaigns2');
        $row $query->result();
        if (!isset($row[0])) {    //not found so get the first one
            $this->db->where('email'$this->session->userdata('userid'));
            $query $this->db->get('campaigns2');
            $row $query->result();
        }

        if (!isset($row[0]->type))
            $row[0]->type 0;          //if not set make is into generic

        //set the premium support flag
        if ($row[0]->premium_support==1)
              $_SESSION['premium_support']=1;
        $this->MyModel->counts_for_three_way();
        //set this to software or pharma or generic or defense
        $this->output->set_template('default2');
        $this->load->js('assets/themes/default/js/jquery-1.9.1.min.js');
        $this->load->js('assets/themes/default/hero_files/bootstrap-transition.js');
        $this->load->js('assets/themes/default/hero_files/bootstrap-collapse.js');
        $this->load->js('js/jquery.orgchart.js');    // for charts
        $testhost getenv('TESTHOST');
        $this->MyModel->update_risk();  //do this everytime a user logs in
        $this->create_cubby();    //attempt to create cubbys for this person
    }

    public function _configure_output($output null)
    {
        $GLOBALS['title'] = "Research Credit Online";
        $this->load->view('configure.php', (array)$output);
    }

    public function index()
    {
        $this->_configure_output((object)array('output' => '''js_files' => array(), 'css_files' => array()));
        $this->_example_output((object)array('output' => '''js_files' => array(), 'css_files' => array()));

        if ($this->session->userdata('onetime')!=1)
        {
            $this->session->set_userdata('onetime'1);
            //load the dashboard
            $this->report_generator_amazing();    <<this displays the dashboard 
            
//load the images
            $this->get_from_locker();  //bring down this guy's images from s3
      }
    
proof that an old dog can learn new tricks
Reply
#4

I'm not sure I understand your problem here. The only method in your Configure controller that can be called from a route is index(). What function are you trying to call that calls index() when it should not?

Also, the order is a little weird to me. In _configire_output() you load a view, but then there's other things going on after that: generating a report, download images from s3, etc. I think loading the view should be the last thing happening since it's outputting the html document to the browser.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#5

(This post was last modified: 11-16-2021, 05:36 AM by richb201.)

"The only method in your Configure controller that can be called from a route is index()."
How do you know that?

"Also, the order is a little weird to me. In _configure_output() you load a view, but then there's other things going on after that: generating a report, download images from s3, etc. I think loading the view should be the last thing happening since it's outputting the html document to the browser."

The images are being downloaded for use later in the application. Generating a report is creating the dashboard with koolreport. It gathers data from some mysql files. 

The configure_output hasn't been modifed in years.

    public function _configure_output($output = null)
    {
        $GLOBALS['title'] = "Research Credit Online";
        $this->load->view('configure.php', (array)$output);
    }

What is configure output normally used for? I am thinking that it is part of the way ci_simplicity works, which I use throughout the application, but not in the dashboard.

Here is the dashboard. http://staging.researchstudyonline.com:8181/
Pressing the Enter link changes the URL but the window doesn't change!
proof that an old dog can learn new tricks
Reply
#6

(11-16-2021, 05:31 AM)richb201 Wrote: "The only method in your Configure controller that can be called from a route is index()."
How do you know that?

Because that's the only public function in the code you posted. Unless you didn't post it all. We can't debug your code if we don't see it...

(11-16-2021, 05:31 AM)richb201 Wrote: What is configure output normally used for? I am thinking that it is part of the way ci_simplicity works, which I use throughout the application, but not in the dashboard.

No idea. I think it's just part of your application. I didn't find this function in CI3 or ci_simplicity's repo.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB