i've a problem in auto-loading the doctrine 2 with codeigniter 2.1.0,
i was following this tutorial
http://www.phpandstuff.com/articles/codeigniter-doctrine-from-scratch-day-1-install-and-setup
i was supposed to open the autoload.php file and load the doctrine like this :
$autoload['plugin'] = array('doctrine');
but the problem is that there is no $autoload['plugin'] = array(); in my autoload.php
so how to load the doctrine ?
That phpandstuff article is too old and for doctrine1. Use this for CI2 and Doctrine2
https://github.com/rubensarrio/codeigniter-hmvc-doctrine
you need to setup a library class and setup doctrine classloader.
If I'm right since the version 2.0 of CodeIgniter the plugin has been removed and has been added the helper class which is almost the same thing.
I thin you should transform your plugin in a helper:
yourplugin_pi.php => yournewhelper_helper.php
and then you can add it in the autoload file in the helper section:
http://codeigniter.com/user_guide/installation/upgrade_200.html
Related
I'm trying to use localization in my Laravel 5.8 application. Following up with this How To Build An Efficient and SEO Friendly Multilingual Architecture For Your Laravel Application I have always do the same steps and have no problems. However, when I try it with Laravel 5.8 I keep getting Class translator does not exist from app()->setLocale(request()->segment(1)); I use that in the app service provider for some reason.
AppServiceProvider
<!-- language: php -->
public function register()
{
app()->setLocale(request()->segment(1));
Schema::defaultStringLength(191);
}
The register method is not to be used for using services.
Try adding your code in the boot method of the class.
Also I believe a better place for adding this is in a middleware then in the service provider.
I'm developing a package, which can be consumed by Laravel applications. The package has a ServiceProvider, which consumers use when they want to instantiate stuff from the package.
Now, I would like to use this ServiceProvider in the package's own tests to resolve dependencies. Integration testing if you will.
How can I do that?
It looks like resolve() depends on app(), so am I correct in assuming that the Laravel service container is not standalone and can only be used inside of an application?
tldr; composer require illuminate/container
The App:: facade resolves to Illuminate\Foundation\Application::class, and the helper functions (including app()) are found in the same namespace. So you'd need to composer require illuminate/foundation to get this.
However, the actual container is at Illuminate\Container\Container - this is the base class which is extended by the Application class above, so you could get a thinned-down version of just the container with composer require illuminate/container.
I should also note that they appear to share the same static::$instance so using the illuminate container should work in both Laravel and non-Laravel apps.
Example resolving an instance, and calling a method with automatic dependency injection:
use Illuminate\Container\Container;
$container = Container::getInstance();
$concrete = $container->make(Some\Abstract\Interface::class);
$result = $container->call([$concrete, 'methodWithDependencies']);
I'm working with laravel 5 and trying to integrate the following package:
exacttarget/fuel-sdk-php
I executed on my project:
composer require exacttarget/fuel-sdk-php
So I had on my vendor dir exacttarget provider.
First thing I've noticed this particular package doesn't use namespaces, so it still calls require directives but not "use \path\namespace"
Is it a right approach? I haven't seen many packages yet but among my past experience doesn't look to me the right approach to write a package...
After this I edit condif/app.php to use ET_Client class.
'providers' => [
...
'ET_Client',
...
],
Once I did this, I got an error: looks like Laravel frmwk tries to instantiate the class, that needs some parameters to work, even if I'm not yet using it (istantiating). It this a normal behavior from Laravel?
Am I missing something ?
The providers array is for registering service provider classes. Unless ET_Client extends Laravel’s base ServiceProvider class, it’s not going to work.
Instead, just add the use statements to your PHP classes as and when you need to use the class:
<?php
namespace App\Http\Controllers;
use ET_Client;
class SomeController extends Controller
{
public function someAction()
{
// Instantiate client class
$client = new ET_Client;
// Now do something with it...
}
}
While building multi-tenancy packages for Laravel 5 I had to find out how to make the paths and namespaces dynamic.
This would involve:
views; adding a template directory dynamically that is available in the root namespace
lang; adding a language directory dynamically that is available in the root namespace
routes; adding a routes file dynamically
config; merging additional configuration files from a dynamic location
vendor; allowing custom vendors and packages to be available from a dynamic location
views
Using a service provider you can use the following in your boot() method for views to be available in the root namespace (view('your-view') instead of view('package::your-view')):
$this->app['view']->addLocation('/your/new/location');
lang
Using a service provider you can use the following in your boot() method where $path is the new path for your root namespace translations:
$app->bindShared('translation.loader', function($app) use ($path)
{
return new \Illuminate\Translation\FileLoader($app['files'], $path);
});
$app->bindShared('translator', function($app)
{
$translator = new \Illuminate\Translation\Translator($app['translation.loader'], $app['config']['app.locale']);
$translator->setFallback($app['config']['app.fallback_locale']);
return $translator;
});
routes
Routes is by far the easiest. Simply include them using a require_once or by using the Laravel method: \File::requireOnce().
config
I used a directory that would allow a tenant to overrule core configs. Please advice there are no security nor sanity checks here so access should be limited.
Using a service provider you can use the following in your boot() method
foreach (\File::allFiles('/path/to/configs') as $path) {
$key = \File::name($path);
$app['config']->set($key, array_merge(require $path, $app['config']->get($key, [])));
}
This will merge existing configurations by overruling their values with the provided config files.
vendor
Really interesting is the possibility to use dynamically loaded classes. In order to do this you will need to use the ClassLoader addDirectories() method in your service provider
\Illuminate\Support\ClassLoader::addDirectories(['/path/to/vendors']);
additional considerations
The above code can be implemented using service providers. In order for a server provider to work you must add them to the config/app.php file under the providers array. Not doing so will not enable any of the code in the service provider.
In Laravel, when a request mapped to a specific controller method is made, does Laravel access/compiles all other controller files or just the file from involved controller?
Most of the classes you create in a Laravel application are loaded as needed. This includes Models, Controllers, Repositories... pretty much everything.
Autoloading is achieved using the PSR-4 spec. If you have a namespaced class like...
<?php namespace \Foo\Bar;
class Baz {}
Then it should live in...
app/Foo/Bar/Baz.php
When this class is used for the first time, the framework will attempt to load the class from that location.