codeigniter calling show_error from a library - codeigniter

I can't manage to call show_error from inside a library file I get
Warning: include(application/errors/error_php.php) [function.include]: failed to open stream: No such file or directory in E:\project\SOURCE\system\core\Exceptions.php on line 167

Perhaps you need to create a CI instance?
To access CodeIgniter's native resources within your library use the get_instance() function. This function returns the CodeIgniter super object.
more here
So perhaps something like
$CI =& get_instance();
$CI->show_error('something is not right here . . . ');
Will do what you want.

Related

How to access settings from `.env` inside the `index.php`

I’m creating a deployment configuration for Laravel project.
On my hosting public/ folder must be moved to another place.
Obviously, since that, I need to change path to the autoload.php and app.php in index.php.
However, I’d like to add and use a parameter which would tell where these files reside. Something like this:
require __DIR__ . '/../' . env('DEP_EXT_FOLDER') . 'vendor/autoload.php';
I think, the most proper place for such a parameter is .env file.
However, I’ve got an error:
Call to undefined function env()
You can't use the env() function before loading the autoloader.
if you absolutely want to use your .env file, you will have to use native php preg_match() for finding your key and using the value after that :)

Need to run wp_query on a separate php file for an ajax call

But it shows:
Fatal error: Class 'WP_Query' not found in
C:\wamp64\www\word\wp-content\themes\word\templates\calendar-function.php
on line 67 .
You need to include wp-load.php (it is present on root folder)
Like -
$abs_path= __FILE__;
$get_path=explode('wp-content',$abs_path);
$path=$get_path[0].'wp-load.php';
include($path);
Add this code to the file calendar-function.php
$abs_path= __FILE__;
$get_path=explode('wp-content',$abs_path);
$path=$get_path[0].'wp-load.php';
include($path);
You should use WP AJAX api, never call the file in the theme directly.
Please refer to the codex:
https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)

Fatal error: Class 'PayPal\Api\Payer' not found codeigniter

I uploaded the paypal php sdk to my codeigniter app inside the libraries/paypal folder.
In the same folder I create a paypal.php file and inside it I insert this code:
<?php
require __DIR__ . '/common.php';
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
class Paypal{
function createPayment(){
$payer = new Payer();
$payer->setPaymentMethod("paypal");
//....
}
}
but when I call this function in my controller I get this error:
Fatal error: Class 'PayPal\Api\Payer' not found in '....'
I don't understand why instead common.php is imported correctly.
In my app I also have the Facebook sdk and I created the same structure to use it and it works
Best way is to follow these steps.
Download the SDK using composer.
Upload the vendor directory into codeIgniter Application root.
Then in the index.php file put this line
include "./vendor/autoload.php";
Now you can access the Paypal SDK and its dependent libraries easily.

could not connect to database in codeigniter

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Home::$db
Filename: core/Model.php
Line Number: 51
updating autoload.php giving http:500 error
You have to load the db library first. In
autoload.php :
$autoload[‘libraries’] = array(‘database’);
It could be any the following:
You must make sure you have set up your database details correctly in the application/config/database.php file. Instruction on what to fill in here are explained on this page of the manual: http://codeigniter.com/user_guide/database/configuration.html
Or it could be that you first need to load the database library by writing the following code above where you have written your query:
$this->load->database();
And to run your query, the code should look roughly like:
$this->db->query('SELECT * FROM mytable');
you must go to autoload and replace $autoload['libraries'] with this $autoload['libraries'] = array('database', 'form_validation');
the guide says:
You can tell the model loading function to auto-connect by passing
TRUE (boolean) via the third parameter, and connectivity settings, as
defined in your database config file will be used:
$this->load->model('model_name', 'model_alias', TRUE);
and you can access the model by its alias like this:
$this->model_alias->method();
or without alias:
$this->load->model('model_name', '', TRUE);
and access the model:
$this->model_name->method();

Cannot autoload/crossload libraries

I’m getting error when trying to autoload ion_auth library
application/config/autoload.php
$autoload['libraries'] = array('database', 'template', 'asset', 'ion_auth/ion_auth');
folder structure:
application/
...
modules/
ion_auth/
...
config/
ion_auth.php
...
tester/
controllers/
tester.php
I try to var_dump($this->ion_auth) on tester.php and get error message:
The configuration file ion_auth.php does not exist.
I try to $this->load->library('ion_auth/ion_auth') from tester.php and remove the ionauth from autoload, It still error. How to solve this?
I download codeigniter from link on codeigniter.com and download Modular Extension from bitbucket
It's not an issue with Modular Extensions. You need to put the config file for Ion Auth into the main application's config folder, not in the Ion Auth directory.
Just move it from application/modules/ion_auth/config/ion_auth.php to application/config/ion_auth.php. That will take care of the config error, but you'll probably need to move the entire Ion Auth library into application/libraries.
I don't use Modular Extensions, but from the looks of your code, I'd venture to guess that CI doesn't know to look in the ion_auth folder for the config folder.
If Modular Extensions has a config option, make sure to set it to look in the extension's folder for a config folder. If it doesn't, you'll need to either tell CI directly about the config folder, or put the ion_auth config file into a recognized config folder.
I'm doing exactly the same as you, HMVC from wiredesignz, CI and Ion_auth and I had the same problem. I solved it loading the config file PRIOR the library, :P, I don't know if this would be your problem, but I also had exactly the same error message. My construct method with Ion_auth looks like
class Auth extends MY_Controller {
function __construct()
{
parent::__construct();
// THIS LINE BEFORE LOAD THE LIBRARY:
$this->load->config('auth/ion_auth', TRUE);
$this->load->library('ion_auth');
$this->load->library('session');
$this->load->library('form_validation');
$this->form_validation->CI = & $this;
$this->load->database();
$this->load->helper('url');
$this->load->helper('cookie');
$this->load->library('email');
$this->load->library('session');
$this->lang->load('auth/ion_auth');
$this->load->model('auth/ion_auth_model');
}

Resources