CodeIgniter Loader extend causes error - codeigniter

I've came across something that drives me crazy. please help me :(
I'm try to extend the CI_Loader Core in-order to create global header and footer.
For some reason, the extending causes error.
The extend code:
class MY_Loader extends CI_Loader
{
function __construct()
{
// i need the codeigniter super-object
// in all the functions
$CI =& get_instance();
}
public function load_header()
{
echo 'header';
}
public function load_footer()
{
echo 'footer';
}
}
The error i currently get
Unable to load the requested file: helpers/url_helper.php
UPDATE: CHANGED THE CODE - NEW ERROR
class MY_Loader extends CI_Loader
{
function __construct() {
parent::__construct();
$CI =& get_instance();
$CI->load = $this;
}
public function load_header()
{
echo 'header';
}
public function load_footer()
{
echo 'footer';
}
}
now i get some error with the header
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /mounted-storage/home75b/sub007/sc43190-SREL/gogetmilk.com/application/core/MY_Loader.php:1)
Filename: libraries/Session.php
Line Number: 672
UPDATE #2
I'm not its the right way to fix it. but its working.
line 672 in libraries/Session.php sets a cookie
i've added a test to see if headers were already sent:
if (! headers_sent() )
{
setcookie(
$this->sess_cookie_name,
$cookie_data,
$expire,
$this->cookie_path,
$this->cookie_domain,
$this->cookie_secure
);
}
its not working ok.
i've created session before printing anything, after printing, within views, after loading views, etc..
does anyone believe this will cause any problems?
problem solved and was not related to codeigniter. see answer at the bottom.

The error i currently get Unable to load the requested file:
helpers/url_helper.php
You're getting this error because you didn't load URL helper. I don't see any call to any URL helper function so I assume the error is being thrown in another file ... Try adding
$this->load->helper('url');
in relevant file or just load it in the config/autoload.php
and, yes, use parent::__construct(); as answered by Broncha

Your construct should call the parent's construct
function __construct()
{
parent::__construct();
// i need the codeigniter super-object
// in all the functions
$CI =& get_instance();
}

Problem solved. it wasn't even a CodeIgniter Issue.
It was an invisble BOM at the begining of the file.
Used this application to remove this bytes: http://sourceforge.net/projects/bomremover/
Thanks everybody for your help :)

Related

configure flexigrid helper, and customize variable $colModel

I try to start Flexigrid into Codeigniter.
I download demo files from here http://gembelzillonmendonk.wordpress.com/2010/06/28/flexigrid-and-codeigniter-with-advanced-searching-with-example/
but i wrong to set up something:
Instruction from site:
extract .rar to CI folder**
open your controller (ie: CI_Folder\system\application\controllers\flexigrid.php)**
configure flexigrid helper, and customize variable $colModel, example:**
code example
What I did:
I installed correctly CodeIgniter (copy and paste inside htdocs - xampp)
I created a database called 'country' and import sql file inside demo.
I copied correctly files an folders from demo files to my CI folder (called grocery-crud-demo).
But when I type on firefox http://localhost/grocery-crud-demo/index.php/flexigrid/index I have this error
Fatal error: Class 'Controller' not found in C:\xampp\htdocs\grocery-crud-demo\application\controllers\flexigrid.php on line 2
A PHP Error was encountered
Severity: Error
Message: Class 'Controller' not found
Filename: controllers/flexigrid.php
Line Number: 2
Backtrace:
I read instruction also from here: http://roadmyapps.toile-libre.org/index.php/flexigrid/examplebut I don't understand which code exactly I must have into flexigrid.php
I don't understand how configure flexigrid helper, and customize variable $colModel.
I need exact code into files. Have you idea?
I find CodeIgniter 1.7.3 -- I repeat steps -- new error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Ajax_model::$db
Filename: models/ajax_model.php
Line Number: 34
Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\grocery-crud-demo\system\application\models\ajax_model.php on line 34
Code of ajax_model.php is this: http://pastebin.com/P3KawC7S
Probably you are using newer version of CI than one on tutorial.
As I can see tutorial is written for 1.7.2 version.
Try to change
class Someclass extends Controller
{
public function someclass()
{
}
public function index()
{
//etc, etc
}
}
with
class Someclass extends Controller
{
public function __construct()
{
parent::__construct()
{
}
}
public function index()
{
//etc, etc
}
}
Also, for models too. Like
public function Ajax_model()
{
parent::Model();
$this->CI =& get_instance();
}
should be
public function __construct()
{
parent::__construct();
$this->CI =& get_instance();
}
Try that way.
Spot those differences. Those should change in every controller and model respectivelly. Follow this link for upgrading your app.
If fail again, see the CodeIgniter documentation about upgrading versions.

Fatal error: Cannot use object of type stdClass - amfphp

I am newbee for Amfphp+codeignitor, I am unable to see the answer for the question amfphp 2.2, index.php gives fatal error?, Or it is not clear to me.
I followed the process mentioned here
http://www.nunomira.com/blog/2012/03/codeigniter-2-0-3-with-amfphp-2-0/
I am getting the same error - Fatal error: Cannot use object of type stdClass as array in D:\vhosts\site\application\libraries\Amfphp\Plugins\AmfphpMonitor\AmfphpMonitor.php on line 167
No Idea where i am doing the mistake.
http://localdomain.com/index.php/amf/gateway is the url i am trying.
How to rectify? what is the problem? if the problem is resolved, will i look service browser?
Experts please guide me on this...
Here is the code
Folder Structure
-controllers
-amf
-services
-Testservice.php
-Gateway.php
-libraries
-Amfphp (Amfphp folder)
Gateway.php
<?php
require_once APPPATH . "/libraries/Amfphp/ClassLoader.php";
class Gateway extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$config = new Amfphp_Core_Config();//do something with config object here
$config->serviceFolders = array(dirname(__FILE__) . "/services/");
$gateway = Amfphp_Core_HttpRequestGatewayFactory::createGateway($config);
$gateway->service();
$gateway->output();
}
}
Testservice.php
<?php
class Testservice extends CI_Controller {
public function getMessage()
{
return array("param1" => "param1");
}
}
Thanks
someone pointed out a similar problem and a fix has been made but not released yet. Could you try replacing your AmfphpMonitor.php code with this one?
https://github.com/silexlabs/amfphp-2.0/blob/master/Amfphp/Plugins/AmfphpMonitor/AmfphpMonitor.php

CodeIgniter Undefined Variable while trying to create subview

Hi I am new to CodeIgniter and am taking a tutorial. I ran into an error
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: subview
Filename: admin/_layout_modal.php
Line Number: 7
An Error Was Encountered
Unable to load the requested file: .php
I followed the tutorial to the tee and I cant seem to find out where I am going wrong.
here is the controller
<?php
class User extends Admin_Controller {
public function __construct() {
parent::__construct();
}
public function login() {
$this->data['subview'] = 'admin/user/login';
$this->load->view('admin/_layout_modal', $this->data);
}
}
and the view
<?php $this->load->view($subview); ?>
Please help...
If you gave script from your .php file not tutorial then everything is ok.
You are probably typing the wrong url in when you try to access the page. Make sure you are loading "admin/user/login" instead of "admin/dashboard/modal".
If you are following tutplus tutorial- building cms with codeigniter, First watch two episodes, Managing User Part 1 and Managing User Part 2 and then Start building, Your question will be answered on Part 2.... the dashboard has to declare the subview variable and
CREATE THAT admin/dashboard/index.php file in views
class Dashboard extends Admin_Controller{
public function __construct(){
parent::__construct();
}
public function index(){
$this->data['subview'] = 'admin/dashboard/index';
$this->load->view('admin/_layout_main',$this->data);
}
public function Modal(){
$this->load->view('admin/_layout_modal',$this->data);
}
}
don't need to pass data to $this. Just pass the data to
$data['variable_name']=data;
pass this $data variable to view through load class.

Extending CI_Controller / Indirect modification of overloaded property [duplicate]

This question already has answers here:
Call to a member function on a non-object [duplicate]
(8 answers)
Closed 10 years ago.
the CI community seems to have no answer to this (or maybe it is so obvious, that it looks like a noob question?), so I ask here.
I've been seeing this kind of error for a long time now (error messages follow), however I have always used this "dirty" workaround. Now I do not want to edit the core CI code anymore, and I know there must be a graceful solution to this.
Here is the setup.
In my application/config/routes I have this
$route['default_controller'] = "dispatcher";
The Dispatcher class in application/controllers/ is defined as this:
class Dispatcher extends MY_Controller {
function __construct() {
parent::__construct();
$this->load->helper(array('form','https'));
}
function index() {
# load models
$this->load->model('site/map');
$this->load->model('site/langs');
$this->load->model('site/pages');
if ( $mapped = $this->map->get_map() ){ // this is the line 21
$this->langs->set_user_lang( $this->GLO['show_lang_in_url'], $this->GLO['show_lang_at_home'] );
$red = base_url().$this->GLO['user_lang_label']."/".$mapped;
redirect($red, "refresh");
}
...
now MY_Controller resides in application/core and is defined as follows:
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
$this->GLO = array();
#
# set defaults:
#
$this->GLO['deb'] = '';
$this->GLO['baseurl'] = base_url();
... (more GLO[key] = value )
}
public function __set ($key, $value ) {
$this->GLO[$key] = $value;
}
Every model I use starts like this (named accordingly):
class Map extends CI_Model {
function __construct(){
parent::__construct();
}
function get_map(){
.....
return true;
}
Now with CI 2.1.2, PHP 5.3.3, Apache 2 on Debian when trying to load a page, I am getting this error:
A PHP Error was encountered Severity: Notice Message: Indirect
modification of overloaded property Langs::$GLO has no effect
Filename: site/langs.php Line Number: 82
A PHP Error was encountered Severity: Notice Message: Undefined
property: Dispatcher::$map Filename: controllers/dispatcher.php Line
Number: 21
Fatal error: Call to a member function get_map() on a non-object in
/home/webdev/MC/_WWW/application/controllers/dispatcher.php on line 21
The line 21 is the one marked above in the Map model
if ( $mapped = $this->map->get_map() ){
the line 82 in the other model looks like this:
$this->GLO['langs'][] = $temp;
Throughout the code, this GLO array is referenced as $this-GLO[key]. It must be read and written from time to time. If I delete the __set function in MY_Controller, I get more of those warnings.
Where is the problem?
Thanks a lot in advance!
I'm not sure about the first error - but these two:
A PHP Error was encountered Severity: Notice Message: Undefined
property: Dispatcher::$map Filename: controllers/dispatcher.php Line
Number: 21
Fatal error: Call to a member function get_map() on a non-object in
/home/webdev/MC/_WWW/application/controllers/dispatcher.php on line 21
...look like you havent loaded your model correctly?
change
if ( $mapped = $this->map->get_map() ){
to
$this->load->model('map');
if ( $mapped = $this->map->get_map() ){

Codeigniter Youtube Data Api by Jim Saunders

I have my consumer key and consumer secret and youtube api key in my config file like so:
$config['youtube_api_key'] = my api key;
$config['google_consumer_key'] = my consumer key;
$config['google_consumer_secret'] = my consumer secret;
I have a controller called youtube_api (made from example.php from jim) and I tried calling the public function:
public function youtube_no_auth()
{
$params['apikey'] = $this->config->item('youtube_api_key');
$this->load->library('youtube', $params);
echo $this->youtube->getKeywordVideoFeed('pac man');
}
I am running into the following problems:
$this->config->item didn't work, i get the following error:
Call to a member function item() on a non-object
I solved this by using config_item('youtube_api_key');
$this->load->library('youtube', $params) gave the following error:
Call to a member function library() on a non-object
I thought there was an issue with scope so I did this $CI =& get_instance() and $CI->load->library, but that didn't work either...
Would someone please kindly point me in the right direction? I'm kind of lost with this issue. I have been searching high and low for an answer but couldn't find one...
The problem was that the example constructor needs this line at the top
parent::__construct
That should fix the issues you were having. So your constructor should look like:
public function __construct()
{
parent::__construct();
$this->load->library('session');
}
There is no need to store CodeIgniter in a private variable. Just use the constructor as outline in the CodeIgniter documentation.
I have updated the GIT repo to fix this issue.
I had a very similar problem, you have to configure it as an object, in your _construct as follow :
class Example extends CI_Controller
{
private $CI;
public function __construct()
{
parent::__construct();
$this->CI =& get_instance();
$this->CI->load->library('session');
$oauth = array();
$oauth['oauth_token_secret']='';
$oauth['oauth_token']='';
}
see here for a very similar subject:
YouTube API Request : How could I get the Right token ( about Jim S.' code )
and
Google Oauth for YouTube : Why do I get "Undefined index: oauth_token" ( Jim S.' code )
let me know if that solved your pb

Resources