I need to use an old library in Laravel which is not PSR-0 compliant.
It consists of several files and directories with a lot of "require", "include" and "require_once" stuff inside. So, I tried to put it into the "libraries/subfolder" and autoload an entry script but it breaks the framework and I constantly get "Class 'Laravel\Response' not found" error. I can't find the reason of this error but I guess that it somehow breaks Laravel's autoloading system.
How to fix this? How can I load this kind of library and keep things working?
Thank you!
If anybody else faces the same problem with Laximo API and Laravel, just use nusoap instead of nusoap_utf8 class.
Related
I have a Codeigniter framework setup that I move cross multiple domain setups as a default starting point. However when I was going to apply it for the first time to a one.com domain I got an error.
An Error Was Encountered
Unable to load the requested class: Form
So far I have tried with checking the source for this. I went into the autoload.php and first tried to change from "form" to "Form" as I found out on another site because of Linux being sensitive to capital letters, but to no use.
I then removed the form all together and then I got the same error, but from the helper "url". I removed that and it went up to libraries and started printing same error for the first in that array.
$autoload['libraries'] = array('Database', 'Session', 'User_agent', 'Upload');
$autoload['drivers'] = array('Form', 'Url');
If there is anything more I can add to shine light on this or make the question better please tell me and I will add it. I am not sure at all where the fault might lie so therefore the information is a bit pale.
You are trying to load a CI helper as a driver ! So the framework looks for a driver Form.php file, which doesn't exist (not in the standard CI installation).
| These classes are located in system/libraries/ or in your
| application/libraries/ directory, but are also placed inside their
| own subdirectory and they extend the CI_Driver_Library class
What you want to do is to load the "form" helper (and the others). A helper is loaded like: $this->load->helper('form'); or autoloaded.
CI - helper
CI - autoload
CI - driver
I just downloaded Laravel 5 and started migrating to it. However, I find the required use of namespaces really annoying.
I don't feel like I am getting much from it, other than cluttering my code.
How can I disable the namespacing requirement?
I don't think you should disable or remove namespaces. The main reason for namespacing is to avoid conflicts with classes that have the same name. As soon as an application gets larger you will have classes that have the same name. Example from the Framework source:
Illuminate\Console\Application and Illuminate\Foundation\Application
Both are called the same. Only because of the namespacing you can import the right class. Of course you could also name them:
ConsoleApplication and FoundationApplication
But while the namespace normally is only used when importing a class at the top of a file:
use `Illuminate\Console\Application`
The name itself is used everywhere in the code. That's something that really clutters up your code, too long class names.
Besides the naming thing, namespaces also encourage better structure and help with knowing where your files are. That's because Laravel's default structure is PSR-4 compliant. That means if you have a controller App\Http\Controllers\HomeController you can be certain that you will find a HomeController.php under app/Http/Controllers.
I am aware of that, but it's not needed in the project I am working on.
Maybe it doesn't make sense for the current project but getting used to namespaces will help you tackle bigger projects in the future
And being a Sublime Text user, which doesn't have autoimport, it really gets to be a pain
I don't know Sublime Text that well, but CodeIntel might have auto import. Otherwise consider switching to another editor / IDE. I can highly recommend JetBrains PhpStorm
In the end, if you still don't want to use namespaces, keep using Laravel 4 or search for another framework that follows less good practices...
Removing namespaces from your app classes
While a totally don't recommend this, it is possible to at least remove some of the namespacing in your application.
For example the default controller namespace App\Http\Controllers can be changed to no namespace at all in RouteServiceProvider:
protected $namespace = '';
And for your models you can just remove the namespace in the file and your good. But keep in mind that without namespaces PSR-4 autoloading won't work anymore. You will have to autoload your files using classmap in composer.json
You can avoid using namespaces for own classes by defining them in the global namespace in your composer.json file. Like this:
"autoload": {
"psr-0": {
"": ["app/Http/Controllers/",
"app/models/",
"app/helpers"
]
},
You will also have to change your app/Providers/RouteServiceProvider.php to:
protected $namespace = '';
for routing to work.
I am using this library and I have made many tables, made lot of functions based on this library and found today that there is no support for where_in().
This library only supports where function:
$this->datatables->where($whereCondition);
CodeIgniter does support where_in(). I tried editing the library but it's a messed up code that I can't understand well. I wanted to add support for where_in but failed to do so.
This is the library:
https://github.com/IgnitedDatatables/Ignited-Datatables/
I even thought I found the solution here
https://github.com/IgnitedDatatables/Ignited-Datatables/pull/56
Someone posted issue with same problem, they said they'd fixed it, I opened their forked file but all I can do there is use
$this->datatables->where_in();
but it doesn't actually run the CodeIgniter where_in query. What can I try to resolve this?
Effectively, there aren't function where_in() in Datatables librairy, but you can use this :
foreach($whereCondition as $w)
{
$this->datatables->or_where('yourColumn', $w);
}
It should be simple, but it's not.
I have a library that is hoping to use other libraries, but something ain't jiving.
Both libs live in system/cms/libraries because as far as I can tell, addons/shared_addons/libraries is utterly useless and the libraries need to be autoloaded (it seems that system/cms is essentially system/application but please correct me if wrong). An aside: just for kicks I put a library in shared_addons/libaries just to see if I could call if from a module; I couldn't. Why is it there?
Lib1
-needs db
-needs lib2
Lib2
-needs session
Here's what happens. Controller [module] loads; calls lib1 which calls lib2 which throws an error. Lib1 is to be called by all module controllers. Lib2 uses session data that is set earlier on and is only called by lib1.
In lib2 I use $CI=get_instance() to supposedly enable CI libs (e.g. database, session). However, I can't get past "Fatal error: Call to a member function userdata() on a non-object"; which is called by
//system/cms/libraries/lib2.php
$this->CI =& get_instance();
//$this->load->library('database'); == "can't find class database"
$ekeyLoc = $this->CI->session->userdata('ronery');
now if I run this in a module controller, it works as expected.
So googling that error, a lot of "db not loaded"'s come up. Just to make sure, I tried to load the database, but because eff me, it can't find class 'database' NB: database is being autoloaded.
When you assign CodeIgniter super object, I'm assuming it's grabbing the whole jabloney, right? I thought so. But to make sure, I decided to try and load the database class in a module/controller, which turns out, because eff me, couldn't be found.
I tried looking through the pyroCMS docs to find out about any trickery, but there ain't much, and none helpful to my situation.
Why can't I load a core library from a module controller?
Why can't I load a core library into a custom library in system/cms/libraries?
Why doesn't the CodeIgniter super object I assign contain session/db crap?
Why can't I load a library from /addons/shared_addons/library?
Why would a call to $this->session->userdata() work from a module controller, but not from a library in the system/cms/libraries folder even though CodeIgniter super object has been assigned?
Thanks.
After 2 days with no answer, I find it both frustrating and hilarious that continuing to search for help inevitably leads to this question being the top google result. FML.
First things first:
$this->load->library('database');
That is not valid CodeIgniter code, like their documentation says it should be:
$this->load->database();
As you've already pointed out though this is autoloaded so there is no need to do that anyway.
Why can't I load a core library from a module controller?
You can.
Why can't I load a core library into a custom library in system/cms/libraries?
You can.
Why doesn't the CodeIgniter super object I assign contain session/db crap?
It does.
Why can't I load a library from /addons/shared_addons/library?
This was not possible in 1.3.x but should have been fixed in 1.3.2, if not has been fixed since in 2.0.
I do not know what you are doing or why you are having such problems, but without any example code or a description of what version of PyroCMS you are using I cannot help any further.
If you have been stuck for two days why have you not posted on our forums? If you HAVE posted on our forums (I didn't see anything about it) you should have put a link in this post to your forum thread to help other people answer the questions.
This is not the first time anyone has been stuck on the internet but you act like it is. Come on, you know how this works! :)
I'm new to codeigniter, and I'm trying to integrate amazon's FPS into my page. There are a bunch of libraries and models that go with Amazon FPS, which I would need included to make the appropriate calls.
How do I include them in CodeIgniter?
I tried placing the entire Amazon folder inside the system/libraries directory, and then tried including libraries with $this->load->library( 'Amazon/FPS/Client' );
However, I run into problems with the relative path there, because Client.php contains the statement require_once ('Amazon/FPS/Interface.php'); ... which is in the same folder.
There has to be a better way to do all this - can anyone please help?
Thanks!!
There is nothing stopping you from directly including classes and working with them however you would in a vanilla PHP setup. If it works in PHP it will work in CodeIgniter.
include(APPPATH.'libraries/Amazon/FPS/Interface.php');
Peng Kong of a3m http://code.google.com/p/a3m/ has a nice way of doing it with plugins:
Example twitter_pi.php
require_once(APPPATH.'modules/account/plugins/libraries/jmathai-twitter-async/EpiCurl.php');
require_once(APPPATH.'modules/account/plugins/libraries/jmathai-twitter-async/EpiOAuth.php');
require_once(APPPATH.'modules/account/plugins/libraries/jmathai-twitter-async/EpiTwitter.php');
/* End of file twitter_pi.php /
/ Location: ./system/application/modules/account/plugins/twitter_pi.php */
In controller
$this->load->plugin('twitter');
$twitterObj = new EpiTwitter($this->config->item('twitter_consumer_key'), $this->config->item('twitter_consumer_secret'));
There is one problem with this in Codeigniter 2.0 there are no plugins
Oh yes codeigniter is nice and has also support for many librarys please have a look here
http://www.haughin.com/code/
Include the Amazon service like this $this->load->library('s3');
#user3526
Note that $this->load->library('classname') will create an instance of that loaded class, not just file (class) include.