I have been trying to write a Controller Plugin which I will be using for user authentication.
I have written the plugin and it should work but I just don't get how to get the plugin loaded... I have read that the Zend Framework has a lot of autoloading possibilities..
My current directory structure:
domains
example.com
Application
configs
controllers
IndexController.php
AuthController.php
ErrorController.php
forms
layouts
scripts
layout.phtml
models
plugins
AuthenticationPlugin.php
views
helpers
scripts
auth
login.phtml
error
error.phtml
index
index.phtml
Bootstrap.php
library
Zend
pubic_html
.htaccess
index.php
Can anyone help me?
Thanks in advance!
Assuming your appnamespace is Application_, then your plugin class should be:
named Application_Plugin_AuthenticationPlugin
stored in the file application/plugins/AuthenticationPlugin.php
registered with the frontcontroller using something like (in application/configs/application.ini):
resources.frontController.plugins.auth = "Application_Plugin_AuthenticationPlugin"
You could create your own library folder with a similar folder structure to Zend's. For instance (assuming your own namespace My_):
library
My
Controller
Plugin
Authentication.php
Authentication.php would contain a class named My_Controller_Plugin_Authentication.
You would then register the namespace in your bootstrap (manual):
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('My_');
Failing that, you could use the structure above using the resource autoloader (manual). Zend Framework expects that classes in those folders are namespace prefixed too, so your class name would be Plugin_AuthenticationPlugin.
Add the following line in for example your Bootstrap file:
Zend_Controller_Front::getInstance()->registerPlugin(new AuthenticationPlugin());
Related
I am abslolutly new in PHP and moreover in Laravel framework (I came from Java).
I am following this tutorial to create a custom authentication driver:
http://laravel-recipes.com/recipes/115/using-your-own-authentication-driver
I have a very newbye doubt: at the beginning of this tutorial it show that I have to create a class that implements UserProviderInterface.
It only show the code but not where this class have to be put into my Laravel project. The only clue about its positioning is the namespace:
namespace MyApp\Extensions;
But exactly where have I to put it?
I have the following structure:
It say to put it into MyApp\Extensions but I have not MyApp and Extension folder in my project? (or maybe the nampespaces name doesn't reflect a directory structure into the project tree?)
So where have I to create this class?
if you want it to go inside MyApp\Extensions, consider MyApp as the app folder.
Then only thing to do is create a folder named Extensions inside app folder and create your UserProviderInterface.php there.
But If I were you, I'd create it under app\Auth\Providers\UserProviderInterface.php
I believe what the page author meant was to create a folder named Extensions and create the provider file under app/Extensions folder. MyApp is just a custom namespace that the author chose, that in default laravel app, it should be App.
Which means, if you create a folder Extensions under app folder, the DummyAuthProvider should then be in the namespace of namespace App\Extensions;
my file structure for phalcon is something like this
--app
-----controllers
-----models
-----views
-----functions
-----libraries
where functions and libraries folder contains some third party scripts like facebook log in etc, when I include the script in my controller classes, I did
include "../functions/facebook.php"
but it gives a file not found error.
How should I include files in the controller classes?
Ideally you should be using an autoloader Phalcon provides for automatically loading classes.
For non-classes, did you try using full path?
include __DIR__ . "/../functions/facebook.php";
I want to use a central CI setup for multiple sites. The way I handle this is I created a package called MPACK and added it to autoload in the config file of each site.
Folder Structure:
/main
/system (CI 2 System folder)
/MPACK
/site1
/application
site2
/application
Inside this MPACK I have share libraries, models, helpers, etc.
However, I would like to have an extended MY_Form_Validation that would be common to ALL sites. Adding the class file to /MPACK/libraries fails. Adding it to /site1/application works fine, as expected.
Is there any way to do this extending inside MPACK?
Thank you for your time.
Please try this:
// Placed your MY_Form_validation.php under MPACK/libraries
$this->load->add_package_path('/path/to/MPACK');
$this->load->library('form_validation');
You can get more information from CodeIgniter User Guide - Loader Class. :)
You can also autoload your package in /application/config/autoload.php : $autoload['packages'] = array('/path/to/MPACK');
EDIT: turn out that the above solution doesn't work, because Loader always look for APPPATH & BASEPATH first, and I not sure modifying this core class won't break something. Here is another solution in theory:
You should have your MPACK form validation lib, and sites' form validation lib should be symlinks to the MPACK one:
/site1/application/MY_Form_validation.php -> /MPACK/libraries/MY_Form_validation.php
If you just use everything from MPACK, nothing specifically for /site1 or /site2, just make a folder link:
/site1/application/libraries/ -> /MPACK/application/libraries/
Hope this help =)
You can read more here: http://codeigniter.com/wiki/Multiple_Applications_via_Symlinks/
I developing a project using Zend framework and I came across the following problem. I'm using Zend framework MVC folder structure generated using their zf.sh script.
My library folder has the Zend library folder and it's classes can be called normally inside the application. I created another folder inside my library for my classes. This is the folder structure now:
MyProject
|_application
|_docs
|_public
|_library
|_Zend
|_Buyers
|_Donations.php
|_scripts
I named my Donation class "Buyers_Donations" as the Zend framework naming convention.
When I tried using this class inside my controller
$obj= new Buyers_Donation();
it gave an error can not find class Buyers_Donation inside the controller.
But when I added the following line in my Bootstrap it worked:
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);
$moduleLoder = new Zend_Application_Module_Autoloader(
array(
'namespace'=>'',
'basePath'=>dirname(__FILE__)
));
Could someone please explain what actually happened and what is the use of the module autoloader although I don't have any modules in my application ?
As you suspected, you shouldn't be using the module autoloader since you're not using modules. Assuming the Zend* classes are autoloading correctly for you, all you need to do is tell the standard autoloader that it should also be used for classes in your 'Buyers' namespace. So instead of the code snippet you posted, just do:
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('Buyers_');
you can also set this in application.ini if you prefer.
I'm also assuming that your classes are in the library folder, and not in the public directory as your question implies (this would be bad).
If you do not wish to use the zend's auto loading feature, you will have to include files manually by using require_once(), such as:
require_once 'Buyer/Donations.php';
If you do wish to use zend loader with your own library code that uses your own namespace, you may register it with the autoloader using the registerNamespace() method. in the bootstrap, you could do so as follows:
protected function _initAutoload()
{
$autoloader = Zend_Loader_Autoloader::getInstance()->
registerNamespace('Buyers_')
return $autoloader;
}
If the auto loader doesn't work, make sure you set the include path to the library folder somewhere. It's automatically added by the zend framework to public/index.php:
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
I'm trying to create a Zend Framework project using PHP 5.3.2 and Zend Framework 1.10.3.
i created the source files of the project using the zend framework tool and the db related classes i created with zend-db-model-generator.
example:
in models directory i have the following:
FbUser.php - class Default_Model_FbUser
FbUserMapper.php - class Default_Model_FbUserMapper
DbTable/FbUser.php - class Default_Model_DbTable_FbUser
The models in the models directory should be included automatically when I use them in one of the controllers, but it seems that it doesn't.
what should i configure in order for the db class models will be auto-included when used ?
update
I tried adding the following code to the bootstrap file:
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Default_');
the autoloader still looks for Default/Model/FbUser.php in include path instead of Model/FbUser.php in the zf project.
I did not need to use Zend_Loader_Autoloader at all, although it's a cool component to auto-load classes in your include path.
i need to add to application.ini which is the main config of the application, the following line:
appnamespace = "Default_"
The program understands the application name space and then loads the db model classes properly.