I have Cakephp 3 application and i want to load this plugin and the event listener below it just for admin prefix. ( not the entire project ) .
how can i achive this?
this is my
config/bootstrap.php
where i load this plugin . (I load these at end of the file )
...
Plugin::load('Josegonzalez/Upload');
\Cake\Event\EventManager::instance()->on(new \App\Controller\Event\AppEventListener());
i want these to line only run on admin prefix
You can't conditionally run code based upon routing inside boostrap.php as the routing configuration for you app hasn't been loaded yet.
You'll have to do it old school style and use $_SERVER['REQUEST_URI'].
$url = $_SERVER['REQUEST_URI'];
$admin = '/admin/';
if(substr($url, 0, strlen($admin)) === $admin) {
Plugin::load('Josegonzalez/Upload');
\Cake\Event\EventManager::instance()->on(new \App\Controller\Event\AppEventListener());
}
Updated
Your plugin should have it's own bootstrap file. Which contains
Upload/config/bootstrap.php:
\Cake\Event\EventManager::instance()->on(new \App\Controller\Event\AppEventListener());
The app's bootstrap then tells CakePHP to include the bootstrap when loading the plugin.
App/config/bootstrap.php:
Plugin::load('Josegonzalez/Upload', ['bootstrap' => true]);
You shouldn't conditionally load your plugin.
I think you are searching for authentication on requests to your plugin. You want to limit use of your plugin only to authorized administrators. That is not a plugin issue. It is an authentication issue and you should be using the Authentication component in your plugin to verify the request is valid, and that the current user is an administrator.
Quoting cakephp plugin docs https://book.cakephp.org/3.0/en/plugins.html#plugin-routes
You can also load plugin routes in your application’s routes list. Doing this provides you more control on how plugin routes are loaded and allows you to wrap plugin routes in additional scopes or prefixes.
So you can do
Router::scope('/', function ($routes) {
// Connect other routes.
$routes->scope('/admin', function ($routes) {
$routes->loadPlugin('Josegonzalez/Upload');
});
});
For your event listener, load it inside plugin bootstrap configuration
// inside plugin bootstra.php
\Cake\Event\EventManager::instance()->on(new
\App\Controller\Event\AppEventListener());
Related
Can anyone help me to create a custom 404 page in laravel 5.7, i am new to laravel so it'd great if you tell me the flow for this.
Thanks
Create 404.blade.php file in errors folder inside your views and make customizations that you want.
OR
You can also use vendor:publish command to publish all the errors blade defined in core.
php artisan vendor:publish --tag=laravel-errors
This will create an errors folder in your views directory and in it there will be all error blade files. You can customize 404.blade.php in it.
#Kamal's solution is good if you want to use a static 404 file. For more customization you can create a proper 404 controller.
To do so first create a controller and method for handling the 404 page (or add a method to an existing controller). Then, tell Laravel to redirect to that controller if no other route was found by adding this at the end of your routes\web.php file. Here's an example:
Route::get('404', 'PageController#render_404_page');
Route::fallback(function () {
return redirect('404');
});
This gives you the freedom to add more logic to 404 pages.
I'm building an AngularJS (1.x) and Ionic/Cordova mobile app for iOS + Android. I'd like to add/create a "deep link" to my Sign In page so that when I send a new user a "Confirm your Email" email and they click a link to confirm their registration, then if they're on their mobile device (with my app installed) they'll be taken into the app directly to the Sign In page.
I see this plugin but I have no experience creating deep links in AngularJS/Ionic/Cordova apps. Any ideas?
If you are unsure about deep linking, it will increase the robotic impressions of your page which will increase the number of crawlers.
If you want to learn more about deep linking visit the following link: http://www.divami.com/blog/deep-linking-angular/
Now, the thing you want to implement is authentication of the existing users making and API call to the server that will check to see if the user already exists. If the user exists they will be taken to the login page else they will be taken to the registration page. This can be achieved using resolvers in angularjs.
Below is a link on how to implement this:
https://medium.com/opinionated-angularjs/advanced-routing-and-resolves-a2fcbf874a1c
Since you are using cordova use this plugin, it will help you started for IOS and Android easily.
Install plugin with URL Scheme with below cmd
$ cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=mycoolapp
That's it, now your app can referenced with
Open my app
You can send authentication code along with your URL like
Open my app
To retrieve code in your App
function handleOpenURL(url) {
console.log("received url: " + url); ==> this will returnURL after://
}
From this you can authenticate the user in your app itself. This is simple way as you are new to deeplinking. Go through the rules in plugin to know more about the naming convention for custom URL(mycoolapp)
Try this plugin it works great.
document.addEventListener('eventName', didLaunchAppFromLink, false);
function didLaunchAppFromLink(event) {
var urlData = event.detail;
console.log('Did launch application from the link: ' + urlData.url);
// do some work
}
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
onDeviceReady: function() {
universalLinks.subscribe('eventName', app.didLaunchAppFromLink);
},
didLaunchAppFromLink: function(eventData) {
alert('Did launch application from the link: ' + eventData.url);
}
};
app.initialize();
As you can see, now you subscribe to an event via universalLinks module when the ready device is fired.
Actually, you can subscribe to it in any place of your application: plugin stores the event internally and dispatches it when there is a subscriber to it.
here is a link the tells how to deep link
https://blog.ionicframework.com/deeplinking-in-ionic-apps/
Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add ionic-plugin-deeplinks --variable URL_SCHEME=myapp --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=example.com --variable ANDROID_PATH_PREFIX=/
$ npm install --save #ionic-native/deeplinks
Add this plugin to your app's module
the below links explains more about that
https://ionicframework.com/docs/native/deeplinks/
IN cakephp 2.x we can configure multiple prefixes in core.php file. like
Configure::write('Routing.prefixes', array('admin','blogger'));
But in cake php 3.X the structure of directory has been changed. There is no core.php file, So how we can configure multiple prefix in cakephp 3.x
Route prefixes get defined in the config/routes.php file in CakePHP 3 using Router::prefix(). So in your case you'd want something like this:-
Router::prefix('admin', function ($routes) {
$routes->fallbacks('DashedRoute');
});
Router::prefix('blogger', function ($routes) {
$routes->fallbacks('DashedRoute');
});
One other change you need to take into account from CakePHP 2.x to 3.x is that prefixes are mapped to sub-namespaces in your application’s Controller namespace. So for example, if you have a Pages model non-prefixed actions would go in PagesController and any actions prefixed admin would reside in Admin/PagesController.
Checkout the documentation on routes for more details.
currently, I run backbone as the front-end of my rails 3.2 application. I need to migrate it into an independent JS application, as part of my putting it as part of Trigger.io.
It now exists as its own index.html file, referencing the assets folder.
When I open the file, it loads the Backbone modules, but the page remains empty. And when I run fetch() commands, it
So, I got a couple of qns:
1) How do I trigger the routes such that it goes to a designated page by default?
I know it gets triggered in Backbone.History.Start, but I am not sure what to do before that.
2) The url is "file://localhost/Users/mingyeow/Desktop/index.html"
How do I set the root url manually to use localhost:3000/my web address?
// define router
var Router = Backbone.Router.extend({
routes : {
'index' : 'indexAction',
'*default' : '_defaultAction'
},
indexAction : function() {
// this will be executed when user navigate to #index
},
_defaultAction : function() {
// this will be executed when user navigate anywhere else (#XXX)
}
});
// on document ready
$(function() {
// initialize router
new Router();
// and start history
Backbone.history.start();
});
You can navigate this way.
Or by clicking the link : Index route
You can use python server. To start it type in the Terminal:
$ python -m SimpleHTTPServer
And check http://localhost:8000
1) To trigger a route change you just need to navigate to a page via a href or JavaScript like window.location. Read up on Backbone Routes but essentially you need to write a function for every 'page'. Each function should take care of rendering the page.
2) This should be very simple. You need a local web server. What I started doing recently is just having a simple Node server. Node is very easy to install and its worth experimenting with. Download a static web server such as this one I made. To use it just put your backbone application in a directory named 'public' and run server.js in node.
If you don't want to do this you can run a simple LAMP/WAMP/MAMP installation and set the root of the Apache web server.
I am building an app with Backbone and Yeoman. I am having an issue with the routing.
I have the following routes set up:
'test' : testMethod,
'' : index
I have set up pushstate:
Backbone.history.start({pushState: true});
I am using Chrome
If enter myApp.com#test the url changes to myApp.com/test and testMethod() fires correctly.
However if I try goto myApp.com/test directly or refresh after the browser has changed the url from # to / then I get a 404.
I am using the Yeoman built in server to test the pages. Could this be causing the issue?
I am not sure if you are using BBB within Yeoman. If you are, this should not be an issue. If you are not using BBB, this is a known issue. BBB has it's rewrite rules setup correctly to use pushstate, but yeoman's built in server does not seem to adopt this. You could edit your grunt.js file with your own rewrite rules to get pushstate working correctly. Some of the users in the above mentioned link have done this successfully.
When your app goes live, you will either need to serve those urls through your server or edit your rewrite rules to do the same. If the latter, and your application relies on SEO, SEO will suffer greatly.