how to require_once in codeigniter - php

I am trying to extend a library in codeigniter. The only way to do so seems to include the original library using require_once then load the extended library using $this->load->library()
right now I have tried
require_once('ion_auth.php');
require_once('home/SITE_NAME/public_html/FOLDER_NAME/application/libraries/ion_auth.php')
require_once('/home/SITE_NAME/public_html/FOLDER_NAME/application/libraries/ion_auth.php')
but unfortunately not luck..... I keep getting this error
Message: require_once(...) [function.require-once]: failed to open stream: No such file or directory
Weird thing is though this works on my local xampp environment but not on the actual server.

Use CodeIgniter's built in constant, APPPATH
require_once(APPPATH.'libraries/ion_auth.php');

If the library is a codeigniter specific library, as sbaaaang points out, you should use:
$this->load->library('ion_auth');
However, if the library is just a generic PHP class or set of functions, the codeiginter loader may not recognize it. Then you will need to use either one of the generic loading operators (include, include_once, require, require_once), with the APPPATH constant, as also pointed out:
require_once(APPPATH.'libraries/ion_auth.php');

Do you know that Codeigniter has a loader class?
change this
require_once('/home/SITE_NAME/public_html/FOLDER_NAME/application/libraries/ion_auth.php')
to
$this->load->library('ion_auth');
and be sure your libraries/ion_auth.php file it's a class named `class ion_auth{}`

Related

Unable to include a php file in typo3

I am using Typo3 cms. Under the main folder I have different other folders such as typo3, typo3conf, fileadmin etc...
I have created two php files named myphp.php, and myantoher.php inside the main folder, and I used require() in myphp.php. But when that line is reached during execution, I am receiving the following errors:
Warning: require(doc/PHPMailer/class.PHPMailer.php): failed to open
stream: No such file or directory in
/var/www/domainname.com/doc/contactform.php on line 3 Fatal error:
require(): Failed opening required 'doc/PHPMailer/class.PHPMailer.php'
Why am I receiving an error when I try to require() this file?
It's very easy to add PHP or any other files in TYPO3
You have to script
includeLibs.cookie = fileadmin/cookie/cookie.php
page.20 = USER_INT
page.20 {
userFunc = user_setcookie
}
For more information about TYPO3 stuff you may visit my blog
https://jainishsenjaliya.wordpress.com/2015/04/01/how-to-include-custome-php-file-in-typo3/
Regards,
Jainish Senjaliya
Here you can include your custom PHP file
Using the CONFIG object.
ex:
config.includeLibrary = fileadmin/templates/myscript.php
Using the PAGE object.
ex:
page.100.file = fileadmin/templates/myscript.php
FYI. it's not possible to use includeLibs via TypoScript anymore. Instead, ensure to encapsulate code in PHP functions or PHP classes, and load them via the class loader (by putting them in a simple extension) or via Composer's autoload functionality.
You can still call functions/methods then via PHP all around TYPO3 an call them in Frontend via
page.10 = USER_INT
page.10.userFunc = bennis_function
or if it is a method in a class
page.10.userFunc = Benni\Mack\RandomClassName->my_method
If you want to do it quick and dirty, you can require your file in your AdditionalConfiguration.php file and use it everywhere as well.
Still, best approach is using an extension with PHP classes and PSR-4 autoloading.

Codeigniter DB Language extension not working

I'm trying to use this extension
But it gives me the following error when loading the library:
Unable to load the requested class: Language
Also if I write MY_Language instead, it gives me the following error:
Fatal error: Class 'CI_Language' not found in C:\wamp\www\ckphp\application\libraries\MY_Language.php on line 79
I am using WAMP and CI v. 2.2.0
Thanks!
I figured it out myself after some more researching...
Apparently the language class is not even in the library folder, but in core folder, meaning it should be placed in the core application/core folder. Also the name is not CI_Language, but CI_Lang, meaning the file name has to be MY_Lang (if MY_ is your prefix). The last thing to change in the extension is
parent::CI_Language();
to
parent::__construct();
and everything should work fine!
Usage:
$this->lang->load('set', 'language'); // To load a language
$this->lang->line('key'); // to display the text
or simply
lang('key'); // if using the language helper
Hope this will help others in the future!
I made a GIST for latest CodeIgniter 3.1.X including with migration to create the database structure
https://gist.github.com/cyberfly/885b320fdf914ae15f7316b22cc72f32

Zend framework retrieving email

When trying to implement this framework I ran into a issue with the directory. When I attemt to use this Zend i end up with
Interface 'Zend\Mail\Storage\Folder\FolderInterface' not found in /home/content/54/9595754/html/zend/library/Zend/Mail/Storage/Imap.php
In the index.php file where I try to display the emails. I use an:
set_include_path
include require_once('Imap.php');
The contents of Imap.php looks like:
namespace Zend\Mail\Storage;
use Zend\Mail;
use Zend\Mail\Protocol;
class Imap extends AbstractStorage implements Folder\FolderInterface, Writable\WritableInterface
So what would i need to add to the Imap.php so that it dosent look inside this directory for the file.
I know understand that I need to try to implement a file in order for the framework to understand the directory they are in however when i try to implement an autoloader I get an error see example below.
require_once '../../../library/Zend/Loader/Autoloader.php';
Yields
require_once(Zend/Loader.php) [function.require-once]: failed to open stream:
No such file or directory in /home/content/54/9595754/html/zend/library/Zend/
Loader/Autoloader.php
Zend framework 2 and most other modern frameworks rely on autoloading for class loading.
You have only required the Imap class but not the dependent interfaces. That's why you get this fatal error.
I'd suggest you setup autoloading in your application. For an example how to set this up you can have a look into init_autoloader.php from the ZendSkeletonApplication.

How to include external PHP classes in Joomla

I have few PHP classes and files that I want to include in Joomla so that I can call those classes. I tried doing require_once config.php to include a PHP file which also includes all the classes that I would want to use in Joomla.
But each time I execute the page I receive the error below:
Fatal error: Class 'SomeClassName' not found
is there any other way to include external PHP classes or files in Joomla?
Thanks in advance!
Please use Joomla autoloader. Is better.
<?php
// Register an adhoc class.
JLoader::register('AdhocClass', '/the/path/adhoc.php');
// Register a custom class to override as core class.
// This must be done before the core class is loaded.
JLoader::register('JDatabase', '/custom/path/database_driver.php', true);
Edit:
Load classes with autoload instead of require/include have a better performance, because PHP will only read (require access to the disk) and compile (require memory and CPU usage) if you really use your class.
To do the same with require/include you have to be sure to only use if will really use the class.
Source:
http://developer.joomla.org/manual/ch01s04.html
require_once should work just fine within Joomla. Make sure the class you want to use is really loaded within your file, and the file is properly referenced in the require_once. Something is going wrong there and it has nothing to do with Joomla itself :-)

Using SimplePie with Yii

I want to be able to use SimplePie on Yii.
I'm using the 1.3-dev version of simplepie
I created a "vendors" folder, put all I had in the .tar.gz in a simplepie subfolder.
Then i add this lines at the beginning of my controller
Yii::import('application.vendors.SimplePie.*');
require_once 'SimplePieAutoloader.php';
spl_autoload_unregister(array('YiiBase','autoload'));
spl_autoload_register(array('SimplePie_Autoloader','autoload'));
spl_autoload_register(array('YiiBase','autoload'));
But when I try to use it, I get this error:
include(SimplePie_Core.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
C:\wamp\www\yii\fr\framework\YiiBase.php(418)
Any ideas why I get this error?
edit: i took the compiled version of simplepie and everything works like a charm
I think (not looked into it fully) that the Simple Pie library follows PSR-0 for class and file names. In which case you should be able to register its path and Yii's autoloader will know how to autoload it. Try adding the following to config.php;
Yii::setPathOfAlias('SimplePie', '/path/to/vendor/');
The second argument needs to point to the root folder of the library e.g. if your path is like this /var/lib/yiiproject/vendor/simplepie/lib/SimplePie then the register the path /var/lib/yiiproject/vendor/simplepie/lib
This yii widget use SimplePie
http://www.yiiframework.com/extension/yii-feed-widget/

Categories