how to use other libraries and classes in agile toolkit? - atk4

We have lot's of classes that in simple PHP applications we can use them simply like this:
require_once "path_to_lib" ;
$lib = new Mylib();
now how can we use these classes in agile toolkit? can we use theme directly in pages and models?
if we should use add-ons could you please give me a simple example with a require in it?
Thanks

You can use any PHP classes as you have discribed, or you can install them by Composer and autoload class of Composer will do the trick with automatic loading of required class.
Add the following into composer.json then run php composer.phar update:
{
"include-path": ["lib/"]
}
Make sure you include Composer's auto-load from the index.php

It's just a PHP so you can use it anywhere BUT this is NOT AGILE way.
One notice.
Use require_once "path_to_lib" ; outside of class
like
require_once __DIR__.'/../../vendor/blah/blah.php';
class blah extends blahblah{
use new inside class
$blah = new Blah();
The GOOD way is to create an addon and use it where you need to.

Related

Target class [App\\Http\\EnsureFrontendRequestsAreStateful] does not exist

I am using Laravel Sanctum to authenticate a react SPA with a laravel API backend.
While I am trying to access routes which does not need authentication, I am getting this error:
"Target class [App\Http\EnsureFrontendRequestsAreStateful] does not exist."
What should I do to guard only some routes, while leaving others open.
You are probably missing the import in the app/Http/Kernel.php file.
// app/Http/Kernel.php
<?php
namespace App\Http;
use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful;
This can usually be solved with: composer dump-autoload
You can read more about what the command does here
composer dump-autoload won’t download a thing. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php). Ideal for when you have a new class inside your project.

cakephp: how do you load a behavior from a plugin?

edit
I used cake bake to make a new plugin and behavior (using --plugin) and it worked. Not sure what I missed.
I'm trying to load the behavior of a plugin. I'm trying to do this with a plugin I wrote for my own use, but I get the same problem when trying to load someone else's.
For example loading https://github.com/Xety/Cake3-Upload
I know you should normally use composer, but this is the way I would load my own plugin.
copy the plugin to \app\plugins\Cake3Upload
load the plugin in bootstrap.php using
Plugin::load('Cake3Upload', ['autoload' => true]);
access the behavior in my model's MyModelTable.php initialize function
$this->addBehavior('Cake3Upload.Upload');
I then get the following error:
Missing Behavior
Cake3Upload.UploadBehavior could not be found.
Make sure your plugin was loaded from config\bootstrap.php and
Composer is able to autoload its classes, see Loading a plugin and
Plugins - autoloading plugin classes
Error: Create the class UploadBehavior below in file:
\app\plugins\Cake3Upload\src\Model\Behavior\UploadBehavior.php
use Cake\ORM\Behavior;
class UploadBehavior extends Behavior
{
}
And what about namespaces ? If u wont use composer u must build the same files tree.
I think it's just about the uploadBehavior have this namespace:
namespace Xety\Cake3Upload\Model\Behavior;
then u only have to follow the plugin doc:
Plugin::load('Xety/Cake3Upload');
and
$this->addBehavior('Xety/Cake3Upload.Upload');
Add 'Xety/' maybe

Grails Asset-pipeline does not load angular partial templates

Im using angular-ui-bootstrap with Grails 2.3.x asset-pipeline:1.6.1 plugin. One of the components - alert.js is attempting to load /template/alert/alert.html but this resolves to 404.
I tried including grails.assets.includes=[*/.html], did not help.
Any workaround for this? Anyway to let asset-pipeline include partial templates?
Is template located in assets, if so remember the first level folders inside of assets are flattened so you may want to nest your templates one more level or adjust your path
I have tried putting the /partials directory under /web-app. It ends up like:
/web-app/partials/content.html
I don't need to mess about with asset-pipeline, it just works!
The versions I use are:
Grails: 2.4.2
compile ":asset-pipeline:1.8.11"
Hope this helps anyone who upgrades their Grails version as well.
thanks for your great blog about AngularJS and Grails, which jumpstarted me on this topic.
Regarding partials, I assume the assets directory is not the right place to put them, because they get concatenated and minified in production mode.
Instead, I use GSP templates as AngularJS partials. For example, I have
views/partials/login.gsp
<div>Hello World!</div>
conf/UrlMappings.groovy
static mappings = {
...
'/partials/login'(view:'/partials/_login')
}
grails-app/assets/javascript/
...
templateUrl: 'partials/login',
...
Advantage: You may even use script lets and taglibs in the partials.
An alternative to using GSP directly would be James Kleeh's approach in this thread.
Best regards,
Björn

How do I install a CakePHP plugin?

More easy questions - this time, how do I install a CakePHP plugin? I get that I take the plugin folder and put it in the, well, the plugins directory.
so
/app
/plugins
/what is this?
And I ask this, because I just downloaded a plugin - here:
http://milesj.me/blog/read/changelog-forum-2.3
And the name of the folder that everything is in is milesj-cake-forum-29a0699
This doesn't appear to be a good plugin name... is there some place that lists or describes what the plugin should be called? I know i know, I'm going to try it out without the 29stuff, but I like things to be silky smooth, not "trial and error".
Yes, I am a terrible programmer.
Based on the plugin's documentation, they refer to models as Forum.Profile for example which suggests that the plugins should be installed in APP/plugins/forum as that's where the CakePHP autoloader will look unless instructed otherwise (section 2).
for example fb plugin ; Load the plugin in your app/Config/bootstrap.php file:
//app/Config/bootstrap.php
CakePlugin::load('Facebook');
You can use all or some of the Facebook plugin as you see fit. At the very least you will probably want to use the Facebook Helper
public $helpers = array('Facebook.Facebook');

CakePHP 2.0 Plugin URL

Trying to get CakePHP work with subfolders for Controllers, Views, or Models is not really working and from what I've read I need to use "Plugins". Right now I have the following folder structure:
/app/Plugin/Manager/
/Controller
CandyController.php
/Models
/View
/Candy
viewCandy.ctp
ManagerAppController.php
ManagerAppModel.php
When I try and set my url to: http://localhost/Manager/Candy/viewCandy/123. I get the error message: "ManagerController does not exist". Why is CakePHP not picking up that it should look in the Manager plugin folder?
Now that 2.0 has been released the docs are fleshed out a bit more. This is described in the Plugin section of the cookbook.
They suggest putting this in bootstrap.php instead of routes.php:
CakePlugin::loadAll(); // Loads all plugins at once
CakePlugin::load('ContactManager'); //Loads a single plugin
Here is the solution:
Go to /app/Config/routes.php and add the line CakePlugin::load(array('YourPluginName')); after the line CakePlugin::routes();. In my case it was line 40.
Basically CakePHP 2.0 doesn't automatically load plugins. I think that's fine and dandy, but there isn't really any documentation for this.

Resources