session_start(): Cannot send session cache limiter - headers > already sent - codeigniter

I knew that this question may mark as duplicate but I can't find my answer from any duplicated post so I decided to post it in my own.
I have a Pages with a session. after all task, there is a button that link into this controller called Profileresult.php but even I do not have a code yet its surprising me that I got this error.
here is the error.
A PHP Error was encountered
Severity: Warning
Message: session_start(): Cannot send session cache limiter - headers
already sent (output started at
/home3/oep2732/public_html/knowyourscore/application/controllers/Profileresult.php:1)
Filename: Session/Session.php
Line Number: 140
Backtrace:
File: /home3/oep2732/public_html/knowyourscore/index.php Line: 315
Function: require_once
I created a controller called Profileresult.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Profileresult extends CI_Controller {
public function index()
{
}
}
?>

Check your controller file. Remove any empty space within that file. For example:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Profileresult extends CI_Controller {
public function index() {
//your codes here
}
}
?>
In your IDE, if you don't have any comment on top of <?php tag, make sure it is in line 1. No empty spaces. Same goes to at the end of ?> tag. If you have empty spaces after that. Those errors will occurs. I've encounter the same problem as yours. I tried to check my controller file as Aman Maurya said, and yes I have few lines of empty spaces. Removed that, that error not display anymore.

Related

localhost is currently unable to handle this request. codeigniter problem

I have this error when i am trying to access a website from wamp, it is done in codeigniter.
Error:
localhost is currently unable to handle this request. HTTP ERROR 500
homeindex controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class HomeIndex extends CI_Controller {
public function __construct(){
parent:: __construct();
$this->load->helper('html');
$this->load->helper('form','url','file');
$this->load->library('session','upload');
}
public function index()
{
//$this->load->view('coming_soon');
$this->load->view('homeIndex');
}
}
route
$route['default_controller'] = 'HomeIndex';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
I am able to access other website which are not done using any frameworks.
This website is done using codeigniter. I am not able to access the website.
Can anyone tell me what is the problem?
Multiple loads with one call are done using an array:
$this->load->helper(array('form','url','file'));
$this->load->library(array('session','upload'));
https://www.codeigniter.com/user_guide/libraries/loader.html#CI_Loader::helper
if that doesn't work turn on error reporting (switch to development mode in index.php) and see what the actual error is. 500 error can be many things...

codeigniter admin route is not working. it returns "The requested URL was not found on this server. "

i need to access the admin controller in codeigniter using the url mywebsite.com/admin
but it returns "The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again" error
my code is
routes.php
$route['admin'] = 'admin/adminmain';
adminmain.php (admincontroller)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Adminmain extends CI_Controller {
public function index()
{
$this->load->view('admin/adminhome');
}
}
In Codeigniter 3 or above controllers name should be capitalized.
The controller file name should be Adminmain.php
controller file name should be Adminmain.php and try to define route like: $route['admin'] = 'admin/Adminmain'; and also check r u defining admin folder under controller folder

Codeigniter HMVC RuntimeException when load model in another modules

I have a new problem with Codeigniter HMVC when deploy my project to hosting Unix (it works well on localhost)
$this->load->model('User_management/Muser_management');
When I call User_management model file in User_profile controllers it throws an error:
Type: RuntimeException
Message: Unable to locate the model you have specified: Muser_management
The same problem with other controllers when when load model from another modules
My structure
>root
>application
>modules
>User_management
>controllers
User_management.php
>models
Muser_management.php
>User_profile
>controllers
User_profile.php
>models
Muser_profile.php
My Muser_mangement file:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Muser_management extends MY_Model{
public function get_listuser()
{
$this->db->select('id,label,email,role');
$user=$this->db->get('user');
return $user->result();
}
}
?>
Please help, thanks
[SOLVE]Anyway, I have fixed it. The solution is:
_the folder name of modules must be in lowercase
_the controller and model files name must be in uppercase for the 1st letter only
_the class in controller and model must be in uppercase for the 1st letter only

How to integrate codeigniter and PHPExcel?

always display an error message on my browser:
An Error Was Encountered
Non-existent class: IOFactory
all classes PHPExcel, i extract on library.
Here it is my controller code
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Report extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
}
public function index()
{
$this->load->library('phpexcel');
$this->load->library('PHPExcel/IOFactory.php');
$objPHPexcel = PHPExcel_IOFactory::load('tandaterima.xlsx');
$objWorksheet = $objPHPexcel->getActiveSheet();
//Daftar barang (4item)
$objWorksheet->getCell('B16')->setValue('UTP');
$objWorksheet->getCell('B17')->setValue('Cross');
$objWorksheet->getCell('B18')->setValue('');
$objWorksheet->getCell('B19')->setValue('');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel5');
$objWriter->save('write5.xls');
}
}
please help me.
Follow the instruction here
https://github.com/EllisLab/CodeIgniter/wiki/PHPExcel
Please remember to remove the PHPExcel_ part in the class name in IOFactory.php. And change the construct function from private to public
ensure that u save PHPExcel/IOFactory.php inside libraries folder and load it as $this->load->library('PHPExcel/iofactory');
You can replace this line
$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel5');
by this line
IOFactory::createWriter($objPHPexcel, 'Excel5');
First you need to place your PHPExcel folder inside thirdparty folder. Then create class file in the library folder. There you need to include thirdparty/PHPExcel file folder and extend the class. After that you can use it in your controller.
And in some Linux Server, you have to care about case.
$this->load->library('PHPExcel');
$this->load->library('PHPExcel/IOFactory');
Codeiginiter 3 supports Composer to use PHPExcel:
In application/config/config.php, set $config['composer_autoload'] to TRUE.
Then you can use Composer to install PHPExcel in Codeiginiter :
composer require phpoffice/phpexcel
Further, You could try PHPExcel Helper to easier handle PHPExcel:
composer require yidas/phpexcel-helper
https://github.com/yidas/phpexcel-helper

Codeigniter 2.0 Can not extend core library

not sure what is the problem? My class that is in Application/core folder, and here it is:
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class MY_Image_lib extends CI_Image_lib {
public function __construct() {
parent::__construct();
}
function tesit($msg) {
log_message('error', $msg);
}
}
I get this error :
Fatal error: Call to undefined method CI_Image_lib::testit()
when I call it like this : $this->image_lib->testit('not working');
What I am missing, this is so strange.
Only the following classes are core classes all others should be extended in library folder.
http://ellislab.com/codeigniter/user-guide/general/core_classes.html
Benchmark
Config
Controller
Exceptions
Hooks
Input
Language
Loader
Log
Output
Router
URI
Utf8
Move your class to the application/library folder and it will override the one in the system folder when you call it.

Resources