zf2 Album with doctrine - doctrine

I installed doctrine and this is working with zfcUser. Now I want install the module Album and I getting the follwoing error:
A 404 error occurred
Page not found.
The requested controller could not be mapped to an existing controller class.
Controller:
album/album(resolves to invalid controller class or alias: album/album)
No Exception available
Can somebody provide my an solution?
The setup is comming from: http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/

It sounds like you may not have loaded the module in your /config/application.config.php
Should look something like this;
<?php
return array(
// This should be an array of module namespaces used in the application.
'modules' => array(
'Application',
'DoctrineModule',
'DoctrineORMModule',
'Album',
),
// etc ...
BTW, I am new to ZF2 and doctrine also - I found this example of the album module using doctrine that actually works and it was a great help to get started ( https://github.com/shanethehat/zf2-doctrine-tutorial )

Related

Codeigniter 4 - controllers won't work unless I add them directly to Routes.php

Can anyone tell me:
Do I have to declare all of my controllers in Routes.php in Codeigniter 4?
I can't seem to get a controller to work unless I add it directly to the "Routes.php"
I have created my controllers properly and the Home controller is working after install and setup.
If I add the controller My_page.php :
<?php
namespace App\Controllers;
class My_page extends BaseController{
public function index(){
echo "Controller 'My_page' -> function index() ";
}
}
?>
I get a
: "404 - File Not Found
Sorry! Cannot seem to find the page you were looking for."
If I now add the controller to the rout - i.e.:
$routes->post('my_page', 'My_page::index');
Then my controller works properly and I get the "Controller 'My_page' -> function index() " when I visit www.mydomain.com/my_page
I have also tested:
www.mydomain.com/index.php/my_page
and this makes no difference.
I am using the .htaccess that comes with the download. I have updated the base URL to www.mydomain.com/
The documentation is confusing to me - https://www.codeigniter.com/user_guide/incoming/routing.html#setting-routing-rules ;
it sounds like they are saying have to declare all classes with routes?
Why are my controllers not working without declaring them specifically in Routes.php?
And am I misunderstanding 'setAutoRoute(true)' it also does not seem to work - I expect that I can turn this on and simply create my controllers pretty much like in CI3?
If you don't enable auto-routing you most certainly need to add all routes which you are allowing, anything else will fail with error 404. As #parttimeturtle mentioned - autoroute it is disabled by default since 4.2.
So in short - Yes, you need to add all controllers, their functions and the appropriate http methods. (That includes CLI routes as well)
You can use $route->add(), which will allow all http methods, it's however more secure to explicitly set them with their methods.

Method App\\Http\\Controllers\\Controller::show does not exist

I just have upgraded one of my project from laravel version 5.2 to 7.1 But now I have started getting following error
Method App\\Http\\Controllers\\Controller::show does not exist.
I know there is not a function named show in my controller class. But if there is any way to trigger custom named method instead of show() while declaring resource attribute in web.php file.
Here is my resource declaration in web.php
Route::resources([
'first', 'FirstController',
'second','SecondController'
]);
Can I make some customization to tackle this situation.

Integrate CHARGEBEE library to LARAVEL

Im starting using LARAVEL last version 7.12 and I'm having an issue trying to integrate CHARGEBEE library to make request to Chargebee api.
I was reading that I can install packages with composer, I did it:
composer require chargebee/chargebee-php:'>=2, <3'
Doing that now I have downloaded chargebee lib here: /vendor/chargebee/chargebee-php/
Now also I saw This stack overflow question here:
That for the user to correctly use this Library-Package I need to create a ServiceProvider so I did:
php artisan make:provider ChargeBeeServiceProvider
then I really don't know how to write the REGISTER() function here, I added also this line: App\Providers\ChargebeeServiceProvider::class, to /config/app.php to 'providers'
ChargebeeServiceProvider
Right now I have a controller: /app/http/controllers/PortalController and I'm trying to use this:
ChargeBee_Environment::configure("sitename","apikeyvalue");
$all = ChargeBee_Customer::all(array( "firstName[is]" => "John",
"lastName[is]" => "Doe", "email[is]" => "john#test.com" ));
foreach($all as $entry){
$customer = $entry->customer();
$card = $entry->card();
}
PortalController
BUT on the frontend it's giving me an error:
Error Class 'App\Http\Controllers\ChargeBee_Customer' not found
Not really sure how i can use this custom Chargebee library here on Laravel.
can somebody please help to integrate in the correct way ?
Thanks!
The real problem here is that ChargeBee_Environment class doesn't exists.
It should be Chargebee\ChargeBee\Environment. And the Models are in their own folder, for example the Portal is ChargeBee\ChargeBee\Models\PortalSession
WPTC-Troop's answer provides some great information on the issue of using a service provider vs library directly, but in the end you need to call the correct classes.
My working code for creating a portal session is below. It would be similar for a Customer object:
\ChargeBee\ChargeBee\Environment::configure("test-site","test_api_key");
$result = \ChargeBee\ChargeBee\Models\PortalSession::create(["customer" => ["id" => "AzZlwTSSVw9871E9g"]]);
$portalSession = $result->portalSession();
$output = $portalSession->getValues();
return $output;
Two things, you can use any third party library as Service Provider(DI) in Laravel or use it directly where ever you needed(mostly in controller)
Not just third party library you can ease the instance creation of class etc in Service Provider. Basically it's for dependency injection, Check IoC in general you'll understand it better.
You tried/mixed both in your case and didn't completely use any single approach.
You've created a Service Provider called ChargeBeeServiceProvider but it doesn't return/bind any resource or no API initialization done in register method. This is where you register and make use of DI. You can bind in properties as well. Here is the official doc to it.
You tried to use directly by initializing ChargeBee_Environment and use ChargeBee_Customer but you didn't mention where to look for this class that is the reason you get the error(Error Class 'App\Http\Controllers\ChargeBee_Customer' not found). I mean compiler will look for ChargeBee_Environment from the same local space but ChargeBee_Environment is available from global scope.
Simple solution to your same code. Add \ to the class to look from global scope or make use of use statement in the top of your file similar to import in java but still we need to require/include the file in php but don't worry, chargebee make use of autoloader(Check here -> composer.json) so it will be loaded automatically in both approach.
\ChargeBee_Environment::configure("sitename","apikeyvalue");
$all = \ChargeBee_Customer::all(array( "firstName[is]" => "John",
"lastName[is]" => "Doe", "email[is]" => "john#test.com" ));
Try the above and let me know. Answered from mobile device. Code is not tested fully(Just copied your and added \ to it).
Excuse brevity :)
I have a solution to use ChargeBee and Laravel. Don't need any: register provider, add to aliases or add path to autoload in composer.json by file path. Just add in use classes that you need in code your Service or your Controller. Like use ChargeBee_Environment and other.
use ChargeBee_Environment;
use ChargeBee_Customer;
ChargeBee_Environment::configure("sitename","apikeyvalue");
$all = ChargeBee_Customer::all(array( "firstName[is]" => "John", "lastName[is]" => "Doe", "email[is]" => "john#test.com" ));
foreach($all as $entry){
$customer = $entry->customer();
$card = $entry->card();
}

Datattables Laravel 5.4 - FatalThrowableError Call to undefined function App\Http\Controllers\Datatables()

I'm using datatables with laravel 5.4, but when I use the datatables()->query():
in providers: Yajra\Datatables\DatatablesServiceProvider::class,
in aliases: 'Datatables' => Yajra\Datatables\Facades\Datatables::class,
My code:
return Datatables()->query( /**query**/ )
return this error in my console:
FatalThrowableError
App\Http\Controllers\Datatables()
I've tried datatables() and Datatables()
Someone with the same problem?
This error happens because Laravel cannot find your package Datatables.
Laravel in controllers, if you are not mapping your classes correctly will always seek the called classes at this point App\Http\Controllers.
Just put use DataTables; or use \Yajra\Datatables\Datatables; at the start of your controller and it shall be fixed. documentation
When you install any package through composer, composer uses namespace to find the package and route functions and classes to it.
you can read more about the namespaces from php.
and you can check this tutorial for namespaces.
Also, Laravel follows the PSR 4 when it comes to autoloading, you can check it from here

Laravel Controller not working

I'm very new to the Laravel framework and am trying to load a simple controller in my browser to slowly get the hang of things.
I have a file that's titled users.php inside of the the laravel/app/controllers/ folder and it looks like this:
class UsersController extends BaseController
{
public $restful = true;
public function action_index()
{
echo 'hi';
}
}
In the routes.php file, I have
Route::get('users', 'UsersController#index');
But, when I go to
http://localhost:8888/laravel/public/users
I'm greeted with a message that says "ReflectionException
Class UsersController does not exist"
I'm not sure if this is because I didn't install the mcrypt extension of PHP. But, when I checked the php.ini file on MAMP, it said that it was enabled. Upon entering
which PHP
in my terminal, it said /usr/bin/php. So, it might not be using the correct version of PHP.
I'm not entirely sure if this is a routes problem or if it's stemming from an absence of a vital PHP extension.
Thanks a bunch!
You need to use the Route::controller method to reference your Controller:
Route::controller('test', 'TestController');
...and rename your file (as Cryode mentions ) to be TestController.php.
Note - if you want to use the filename as test.php, then you will need to use composer to update the autoload settings.
Finally, the format of names for Controller methods changed in Laravel 4, try renaming the method
public function action_index() {}
to be
public function getIndex() {}
the get represents a HTTP GET request... the same applies for post (HTTP POST) and any (GET or POST.. )
I'm not familiar with that part of Laravel's source, so I'm not entirely certain that this is the issue, but your controller file name should match the controller class name, including capitalization.
So users.php should be UsersController.php. Now, when I do this myself on purpose, I get a "No such file or directory" error on an include() call, so that's why I'm not certain that's the sole cause of your problem. But it may be a start.

Resources