• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cannot access controller methods with cron

#1
[eluser]waynusanus[/eluser]
I am pulling my hair out trying to access a controller function via cron.
If I navigate to the function via a browser then all works well. However when I try with cron all that is returned is session info. I have tested with echo statements and found that none are returned via cron when placed after
Code:
$this->load->module($this->module);
not being au fait with codeigniter I just can't seem to figure this out.

Welcome.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends MX_Controller {

/**
  * Index Page for this controller.
  *
  * Maps to the following URL
  *   http://example.com/index.php/welcome
  * - or -  
  *   http://example.com/index.php/welcome/index
  * - or -
  * Since this controller is set as the default controller in
  * config/routes.php, it's displayed at http://example.com/
  *
  * So any other public methods not prefixed with an underscore will
  * map to /index.php/welcome/<method_name>
  * @see http://codeigniter.com/user_guide/general/urls.html
  */


public $is_frontend = 1;
public $is_backend = 0;
public $module = 'dashboard';
public $method = 'index';
public $page   = 'default';
public $coreModules = array();
public $data   = array();

function __construct()
{
  parent::__construct();
  
  $this->data['logged_in'] = $this->session->userdata('logged_in');
  $this->data['segment'] = $this->uri->segment(1);
  $this->data['left_menu'] = $this->session->userdata('gblAdminMenu');
  $this->data['menu_list'] = $this->session->userdata('gblMenuList');
  if((!in_array($this->data['segment'], array_keys($this->data['menu_list']))) && ($this->data['logged_in']))
  {
   redirect($this->module);
  }

  //redirects when session is empty
  if((!$this->data['logged_in']) && ($this->data['segment'] <> $this->module))
  {
   //redirect($this->module);
  }  

  //fetching core modules from database
  $core_modules = $this->mdl_common->get_core_modules();

  foreach($core_modules as $core_module)
  {
   $this->coreModules[] = $core_module->alias;  
  }

  $this->load->modules($this->coreModules);

  if($this->module <> $this->data['segment'])
  {  
   $this->module = $this->data['menu_list'][$this->data['segment']]['module'];
  }
          
  $this->load->module($this->module);            
}

public function index()
{
  $module = $this->module;
  $method = $this->method;
      
  if(class_exists($module))
  {
   $class_methods = get_class_methods($module);  
  
   $segment = 1;
   if(count($this->uri->segment_array()) > 1)
   {
    $segment = 2;
   }

   for($i = $segment; $i > 0; $i--)
   {
    if(in_array($this->uri->segment($i), $class_methods))
    {
     $method = $this->uri->segment($i);
     break;
    }    
   }
                        
   if(in_array($method, $class_methods))
   {
    $this->$module->__construct($this->data['menu_list']);
    $this->data['module'] = $this->$module->$method();
    $this->parser->parse($this->page, $this->data);
   }
   else
   {
    show_404();
   }
  }
  else
  {
   show_404();
  }
}
function test(){ echo 'hello'; }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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