Add custom Eloquent ORM models to WHMCS version 6 - php

WHMCS version 6 uses the Eloquent model.
Their using models documentation clearly states how to access the WHMCS database.
The problem I am experiencing is that I want to access my own model. I have multiple models, some that access WHMCS directly, and other that access a completely separate database.
To use their model, you do this:
...
use WHMCS\User\Client;
...
I tried simply to do this:
...
use WHMCS\User\Client;
use Radius\User\Logon;
...
I added my models to $root_folder/includes/classes/Radius/User/Logon.php mimicking the folder structure of WHMCS.
However, I get an error Fatal error: Class 'Radius\User\Logon' not found in /var/www/vhosts/snowball.co.za/wh6.snowball.co.za/modules/servers/radius/radius.php on line 543
I fully suspect I have to update Composer to recognise my own models, but I am not sure. What I do needs to be fully integrated with WHMCS and it must not break anything.
Does anyone have advice?

You may need to update your autoloaders.
Thank you for posting the solution - others will no doubt appreciate it.

Related

CakePHP error: cake bake is using the wrong table name

Using CakePHP 2.x
I have successfully generated many models, controllers, and views but one of them is just not working.
the database table is name 'server_cpu', The model appears to generate fine as I have compared it to other models that can be turned into controllers and views and it is identical. It also does have the useTable = 'server_cpu', but even still when I try to generate the Controller it tells me that the model has to have a table. After looking closely I believe that it is trying to use the table 'server_cpues', How can i force it to use 'server_cpu' and not 'server_cpues', note that I have tried emptying the /tmp/cache/ folder and that has no effect.
The error when attempting to generate a controller for 'ServerCpus' using cake bake: 'You must have a model for this class to build basic methods. Please try again.'
There are two possible solutions:
Firstly: simply changing the name of the table can resolve this problem, but it should be noted that for many this is not a possibly depending on the stage of development, for example if the current database is well established and used by many other systems or application this may not be possible. If you are starting from scratch this will be an easier solution.
Secondly: a slightly more complex solution would be to work with Inflectors to change the behavior of CakePHP. This can be done by modifying the file '/app/Config/bootstrap.php' to add a custom Inflector, for documentation on this refer to this for information on inflectors for CakePHP 2.x. For this particular situation you could use something like
Inflector::rules('plural', array('rules' => array( '/(.*)cpu$/i' => '\1Cpu' ) ));
Note the use of regex to recognize all string containing cpu

Laravel: Know What to Implement in model

I am just about three days old in laravel, yesterday I tried creating an authentications system using eloquent, so without looking I deleted the default User model, and then I tried creating my own from what I had read from the documentation. After setting up every thing as I had studied and understood, I tried running my app, but whenever I enter the correct username and password I get this error
Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials()
must be an instance of Illuminate\Auth\UserInterface, instance of User given, called in dir
I did not know what the EloquentUserProvider was or where it was even coming from. My original model looked like this
class User extends Eloquent {}
I battled with this error for the whole day (no exaggeration), But today I found out from this SO Can't authenticate user in laravel that it was because I had not implemented some interface, so they linked me to https://github.com/laravel/laravel/blob/master/app/models/User.php where I copied the default model I initially deleted.
I used the documentation almost through out my learning process, and no where in the documention for authentication and for eloquent did they mention that we are suppose to implement these interface for us to be able to use Auth::attempt() method, my question now is how then do we (newbies) know what to implement and what not to implement, or what any of these interfaces even do.
This is simple. It's a laravel's requirement. The User model is generated by default for you. If you do not need to implement the interface's methods, just add them empty in your User class.
And of course, in your case, what to extend or implement will be shown as errors on startup. Reading them carefully can give you all the asnwers.
Also, if you want to use different User Authentication features, or extend the existing ones, you can look some info here in the docs

Making a custom class available anywhere using Laravel

In this stackoverflow post,
Get the query executed in Laravel 3/4
Ricardo Rossi provided a great answer about using Kint and a custom class to easily output information about a Laravel query created using the query builder.
I was able to setup Kent using composer but am new to Laravel and haven't used PHP since version 4.
Could someone please provide an example describing how to create a class which can then be called from anywhere. In his example, Ricardo says he uses "DBH::q()".
At the moment, I'm stuck requiring common files just like in good old PHP4 days.
Thanks
You likely want to use psr-0 auto loading with a namespaced class. Here's a post on setting up laravel which says how to do that.
If I understand your question correctly you are asking how to go about using the following syntax DB::q() using your own custom class...
Laravel uses Facades throughout its design which enables you to access classes from anywhere in your app using static style syntax (e.g. Input::get() or Route::get()). I note Fideloper has also provided an answer to your question... He has an excellent tutorial about how to wrap your own custom class in a Facade so you can use this syntax for your own classes and also sidestep the need to inject the dependency in any class that uses it (i.e. once set up correctly it can be called upon anywhere in your app).
Fideloper tutorial is here...
Hope that helps - Good luck

Override Laravel 4 Package view

I want to create my custom CMS and I'd like to create a user package in which I will have a controller with showProfile() function. But the problem is I'd like to easily edit this profile view. So I want to know if there is a way to create cascade view. Like if there is no file in app/views/ then vendor/vendor/package/src/views will be loaded. I hope you got this idea :)
EDIT:
I managed to make it work. I had to register new namespace for views in my ServiceProvider.
I put this code to ServiceProvider:
\View::addNamespace('cmscore',array(app_path()./'views/packages/zaalbarxx/cmscore');
Where zaalbarxx/cmscore is vendor/package and cmscore is a namespace I can use later in controller like View::make('cmscore::index'). I added this code in boot() method BEFORE $this->package() so this way app/views are prioritized over package/views. Works brilliant.
It is already possible, however the structure would be it look into vendor/package-name/src/views by default, but if there is the equivalent in app/views/packages/package-name/ that would be chosen.
As stated, you should be able to load package views already.
However, you can add more view locations in the array found in app/config/view.php.
Additionally view paths can be added at run-time with the addLocation() method found in the FileViewFinder class.
Using that method that in a service provider would look like:
$app['view.finder']->addLocation('/path/to/views');
Or anywhere in your app:
App::make('view.finder')->addLocation('/path/to/views');
Also note, I answered this question on cacheing view output recently, which might help you see how extending some portions of the View package might work if you choose to go down that route.
You don't need to program this behavior in, if you read the laravel code you will see that this is built in...
Packages by default will first look in and
app/views/packages/package-name/ (all in lowercase! even if package or author have caps! goes unnoticed on windows and then on linux you will bump your head against the wall! )
and if the customer app view doesn't exist the package views will load from the package itself inside:
vendor/author/package-name/src/views

1 abstract method and must therefore be declared abstract or implement the remaining methods

I recently upgraded my magento store to 1.7.0 version from 1.5.1. Most of the things are working as it should be, but when I got to Shipping Method option via admin area I get following error.
Fatal error: Class Zenprint_Ordership_Model_Shipping_Carrier_Ups contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Mage_Usa_Model_Shipping_Carrier_Abstract::_doShipmentRequest) in /home/dev/public_html/app/code/community/Zenprint/Ordership/Model/Shipping/Carrier/Ups.php on line 33
On line 33 of Ups.php this is the code.
extends Mage_Usa_Model_Shipping_Carrier_Abstract
I checked all the modules via Magento Connect and they are all updated to stable version. Is there anything that I missed while upgrading?
The 1.6.x branch of Magento re-factored how the Mage_Usa_Model_Shipping_Carrier_Abstract works, which included adding an abstract method that all child classes must implement.
You have a module named Zenprint_Ordership on your system, which includes a shipping carrier class. It's probably a part of this extension.
This extension has not been updated to work with Magento 1.6+. To get your store working again you should disable this extension by renaming/removing the file
#rename so it doesn't have a xml extension to disable
app/etc/modules/Zenprint_Ordership.xml
app/etc/modules/Zenprint_Ordership.xml.disable
This will remove whatever custom functionality you were using Zenprint_Ordership for, but should return your system to working order.
Long term you'll either need to
Re-code the Zenprint_Ordership module to work with your system, as it looks like the developer hasn't update it since Magento 1.2.
Find an alternative for whatever functionality you were using Zenprint_Ordership for.
Also, even after disabling the extension you may run into problems when viewing old orders that used this shipping method. If you're feeling up for it defining a blank _doShipmentRequest method on the class may help you work around this, but I'm not sure I'd recommend it to a non-programmer.
The high level solution? A ecommerce system, like any complex web application, requires constant maintenance. If you're hosting your own cart make sure you have access to people with the expertise to help you when you run into situations like this.

Categories