Extend CI's controller to automatically load language files
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
|
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@@ -24,19 +24,16 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for Ajax requests.
|
* Controller for Ajax requests.
|
||||||
*
|
*
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class Ajax extends CI_Controller {
|
class Ajax extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
// load language file
|
|
||||||
$this->lang->load(strtolower($this->router->class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,14 +27,14 @@
|
|||||||
*
|
*
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class api extends CI_Controller {
|
class Api extends CI_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the state of a given job.
|
* Update the state of a given job.
|
||||||
*
|
*
|
||||||
* Because we do not want any access from servers we do not trust,
|
* Because we do not want any access from servers we do not trust,
|
||||||
* we need a special secret to authenticate the servers.
|
* we need a special secret to authenticate the servers.
|
||||||
*
|
*
|
||||||
* @param type $secret The secret to authenticate the server.
|
* @param type $secret The secret to authenticate the server.
|
||||||
* @param type $job_id The job id that is running on the server.
|
* @param type $job_id The job id that is running on the server.
|
||||||
* @param type $state The state of the job.
|
* @param type $state The state of the job.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* @author Eike Foken <kontakt@eikefoken.de>
|
* @author Eike Foken <kontakt@eikefoken.de>
|
||||||
*/
|
*/
|
||||||
class Auth extends CI_Controller {
|
class Auth extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
/**
|
/**
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class Dashboard extends CI_Controller {
|
class Dashboard extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -35,9 +35,6 @@ class Dashboard extends CI_Controller {
|
|||||||
$this->load->model('job');
|
$this->load->model('job');
|
||||||
$this->load->model('project');
|
$this->load->model('project');
|
||||||
$this->load->model('user');
|
$this->load->model('user');
|
||||||
|
|
||||||
// load language file
|
|
||||||
$this->lang->load(strtolower($this->router->class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index() {
|
public function index() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
/**
|
/**
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class Jobs extends CI_Controller {
|
class Jobs extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -33,9 +33,6 @@ class Jobs extends CI_Controller {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('job');
|
$this->load->model('job');
|
||||||
|
|
||||||
// load language file
|
|
||||||
$this->lang->load(strtolower($this->router->class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,11 +42,11 @@ class Jobs extends CI_Controller {
|
|||||||
$query = $this->db->order_by('progress', 'desc')
|
$query = $this->db->order_by('progress', 'desc')
|
||||||
->get_where('jobs', array('started_by' => $this->session->userdata('user_id')));
|
->get_where('jobs', array('started_by' => $this->session->userdata('user_id')));
|
||||||
$jobs = $query->result_array();
|
$jobs = $query->result_array();
|
||||||
|
|
||||||
for($i=0; $i<count($jobs); $i++) {
|
for($i=0; $i<count($jobs); $i++) {
|
||||||
$jobs[$i]['project_name'] = $this->db->select('name')->get_where('projects', array('id' => $jobs[$i]['project_id']))->row()->name;
|
$jobs[$i]['project_name'] = $this->db->select('name')->get_where('projects', array('id' => $jobs[$i]['project_id']))->row()->name;
|
||||||
$progress = $jobs[$i]['progress'];
|
$progress = $jobs[$i]['progress'];
|
||||||
|
|
||||||
switch($progress) {
|
switch($progress) {
|
||||||
case -1:
|
case -1:
|
||||||
$progress = lang('waiting');
|
$progress = lang('waiting');
|
||||||
@@ -64,9 +61,9 @@ class Jobs extends CI_Controller {
|
|||||||
$progress = $progress . "%";
|
$progress = $progress . "%";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$jobs[$i]['progress'] = $progress;
|
$jobs[$i]['progress'] = $progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->output
|
$this->output
|
||||||
->set_content_type('application/json')
|
->set_content_type('application/json')
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
/**
|
/**
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class Programs extends CI_Controller {
|
class Programs extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -33,9 +33,6 @@ class Programs extends CI_Controller {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('program');
|
$this->load->model('program');
|
||||||
|
|
||||||
// load language file
|
|
||||||
$this->lang->load(strtolower($this->router->class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,19 +40,19 @@ class Programs extends CI_Controller {
|
|||||||
*/
|
*/
|
||||||
public function index() {
|
public function index() {
|
||||||
$programs = $this->program->getAll();
|
$programs = $this->program->getAll();
|
||||||
|
|
||||||
$tpl['programs'] = $programs;
|
$tpl['programs'] = $programs;
|
||||||
$this->load->view('program/list', $tpl);
|
$this->load->view('program/list', $tpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show detailed information about a program.
|
* Show detailed information about a program.
|
||||||
*
|
*
|
||||||
* @param type $prg_id The program's id
|
* @param type $prg_id The program's id
|
||||||
*/
|
*/
|
||||||
public function detail($prg_id) {
|
public function detail($prg_id) {
|
||||||
$program = $this->program->getById($prg_id);
|
$program = $this->program->getById($prg_id);
|
||||||
|
|
||||||
$tpl['program'] = $program;
|
$tpl['program'] = $program;
|
||||||
$this->load->view('program/detail', $tpl);
|
$this->load->view('program/detail', $tpl);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
/**
|
/**
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class Projects extends CI_Controller {
|
class Projects extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -34,9 +34,6 @@ class Projects extends CI_Controller {
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('project');
|
$this->load->model('project');
|
||||||
$this->load->model('trial');
|
$this->load->model('trial');
|
||||||
|
|
||||||
// load language file
|
|
||||||
$this->lang->load(strtolower($this->router->class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
|
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@@ -24,10 +24,10 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Result browser.
|
* Result browser.
|
||||||
*
|
*
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class Results extends CI_Controller {
|
class Results extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -37,11 +37,8 @@ class Results extends CI_Controller {
|
|||||||
$this->load->model('program');
|
$this->load->model('program');
|
||||||
$this->load->model('job');
|
$this->load->model('job');
|
||||||
$this->load->model('server');
|
$this->load->model('server');
|
||||||
|
|
||||||
// load language file
|
|
||||||
$this->lang->load(strtolower($this->router->class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index() {
|
public function index() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
/**
|
/**
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class Settings extends CI_Controller {
|
class Settings extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -33,9 +33,6 @@ class Settings extends CI_Controller {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('program');
|
$this->load->model('program');
|
||||||
|
|
||||||
// load language file
|
|
||||||
$this->lang->load(strtolower($this->router->class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
*
|
*
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class Trials extends CI_Controller {
|
class Trials extends MY_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -37,9 +37,6 @@ class Trials extends CI_Controller {
|
|||||||
$this->load->model('trial');
|
$this->load->model('trial');
|
||||||
$this->load->model('program');
|
$this->load->model('program');
|
||||||
$this->load->model('project');
|
$this->load->model('project');
|
||||||
|
|
||||||
// load language file
|
|
||||||
// $this->lang->load(strtolower($this->router->class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
20
application/core/MY_Controller.php
Normal file
20
application/core/MY_Controller.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php defined('BASEPATH') || exit("No direct script access allowed");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends CI's controller class.
|
||||||
|
*
|
||||||
|
* @author Eike Foken <kontakt@eikefoken.de>
|
||||||
|
*/
|
||||||
|
class MY_Controller extends CI_Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the parent constructor and loads the relevant language file.
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
// load relevant language file
|
||||||
|
$this->lang->load(strtolower($this->router->class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user