Codeigniter Youtube Data Api by Jim Saunders - codeigniter

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

Related

Laravel Backpack - getting current record from crud controller

In my crud controller I am trying to get the name of the person who is currently being edited.
so
http://192.168.10.10/admin/people/93/edit
In the people crud controller
public function setup() {
dd(\App\Models\People::get()->first()->name)
}
This returns the first person not the person currently being edited.
How do I return the current person (with an id of 93 in this example)
Ok, So since you use backpack look into CrudController to see how the method looks:
public function edit($id)
{
$this->crud->hasAccessOrFail('update');
$this->data['entry'] = $this->crud->getEntry($id);
$this->data['crud'] = $this->crud;
$this->data['fields'] = $this->crud->getUpdateFields($id);
$this->data['id'] = $id;
return view('crud::edit', $this->data);
}
So now you can overwrite the edit function and change whatever you want. You can even create a custom edit page if you so wish.
Setup on the other hand is usually used to add things like
$this->crud->addClause(...);
Or you can even get the entire constructor and put it in the setup method because setup call looks like this:
public function __construct()
{
// call the setup function inside this closure to also have the request there
// this way, developers can use things stored in session (auth variables, etc)
$this->middleware(function ($request, $next) {
$this->setup();
return $next($request);
});
}
So you could do something like \Auth::user()->id;
Also it's normal to work like this. If you only use pure laravel you will only have access to the current id in the routes that you set accordingly.
Rahman said about find($id) method. If you want to abort 404 exception just use method findOrFail($id). In my opinion it's better way, because find($id)->name can throw
"Trying to get property of non-object error ..."
findOrFail($id) first fetch user with specified ID. If doesn't exists just throw 404, not 500.
The best answer is:
public function edit($id)
{
return \App\Models\People::findOrFail($id);
}
Good luck.
you need person against id, try below
public function setup($id) {
dd(\App\Models\People::find($id)->name);
}

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 Form Validation in Codeigniter call to a member function on a non-object error

I know this has been asked before, and I've looked through every answer posted, but to no avail. Basically, I am trying to extend the Codeigniter form validation library on a CI2+ project, but every single time I get the error:
Fatal error: Call to a member function get_errors_array() on a non-object
Below is my code:
application/core/CB_Form_validation.php
class CB_Form_validation extends CI_Form_validation{
function __construct($rules = array()) {
parent::__construct($rules);
log_message('debug', "CB_Form_validaiton class initialized");
}
public function get_errors_array() {
return $this->_error_array;
}
}
and then in my ajax file I have the construct etc.
public function save(){
if($this->form_validation->run() == FALSE){
}
}
and inside that if statement I have tried the following:
echo $this->form_validation->get_errors_array();
echo $this->cb_form_validation->get_errors_array();
echo get_errors_array();
I have also tried placing the CB_Form_validation.php in application/libraries as well. Just as well, I have also tried this in my construct of my ajax controller
$this->load->library('CB_Form_validation');
$this->load->library('core/CB_Form_validation');
And I have set CB_ as my custom class prefix
Turns out that to fix this, you should do the following:
Move your custom form validation class to the application/libraries folder
You can keep the construct of your custom class how it is
Use $this->form_validation->method() to access the function you would like
As long as your loading the form_validation library, you don't need to perform $this->load->library('custom_class') because CI picks up on your custom prefix anyways
Hope this helps someone

CodeIgniter Loader extend causes error

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 :)

Resources