yii class is not loading - php

While trying to include my own class library in Yii. I used this code to include a class file in Yii.
Yii::import('application.apis.myapi.*');
myfile lies at [protected/apis/myapi.php]
I don't know I am getting this error:
[YiiBase::include(myapi.php) [<a href='function.YiiBase-include'>function.YiiBase-include</a>]: failed to open stream: No such file or directory]

I think you should import as
Yii::import('application.apis.*');
It will import all php files under directory applications/apis/.
Yii::import('application.apis.myapi'); //only one file
EDIT: also check this question: Yii import functionality

Maybe you override basePath for your application? (look at protected/config/main.cfg)

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.

how to require_once in codeigniter

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{}`

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.

Magento trying to autoload class unnecessarily

I'm using a 3rd party php library to connect to Microsoft Dynamics CRM, which I've placed in the /lib folder of Magento.
I've created a controller for testing purposes, in which I'm including the files from the lib folder (which are being included, as changing the paths throws an error), but when I try and initiate the class defined in one of the included files, i get this warning:
Warning: include(DynamicsCRM2011\Connector.php) [function.include]: failed to open stream: No such file or directory.
It shouldn't be trying to include anything, the class is already defined in a previously included file!
Any ideas how I can prevent this from happening? I'd have thought it would only try to autoload the file if the class is undefined surely?

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