I configure YII-BOOTSTRAP using these steps
http://www.cniska.net/yii-bootstrap/setup.html
But unable to configure & Get the below error, as shown below: Any ideas?
Controller.php is the base class for all controllers in Yii. Make sure you're autoloading it by having this in config.main
// autoloading model and component classes
import'=>array(
...
'application.components.*',
....
),
Related
I an trying to include a file into the Symfony 4 routes, and can't figure out what would be the correct way to put in the Bundle name.
My routes.yml:
icatcher_builder:
# loads routes from the given routing file stored in some bundle
resource: '#ICatcher/Builder/Resources/config/routes.yaml'
My bundles.php:
App\ICatcher\Builder\Builder::class => ['dev' => true, 'test' => true],
And I get this error:
An exception has been thrown during the rendering of a template
("Bundle "ICatcher" does not exist or it is not enabled. Maybe you
forgot to add it in the registerBundles() method of your
App\Kernel.php file? in #ICatcher/Builder/Resources/config/routes.yaml
(which is being imported from "[PATH]\config/routes.yaml"). Make sure
the "ICatcher/Builder/Resources/config/routes.yaml" bundle is
correctly registered and loaded in the application kernel class. If
the bundle is registered, make sure the bundle path
"#ICatcher/Builder/Resources/config/routes.yaml" is not empty.").
If I just copy the routes into the main route.yml file instead of including an external resource - all works fine.
Symfony has strict rules of naming Bundle classes, which I found out here in the documentation:
https://symfony.com/doc/current/bundles/best_practices.html
So my Bundle class is now re-named from App\ICatcher\Builder\Builder to App\ICatcher\Builder\ICatcherBuilder and the file is re-named the same way ICatcherBuilder.php and it works.
I wrote a class CronTab_Manager to generating and managing cron jobs whith PHP. Now I want to access it everywhere in my project.
In my config file I set path of alias like below:
$cronTab = dirname(dirname(dirname(__FILE__))).'/extensions/CronTab_Manager';
Yii::setPathOfAlias('cronTab',$cronTab);
And also import that class in this way:
'import'=>array(
'application.models.*',
'application.components.*',
'cronTab.*',
),
My class isn't extended from other classes, and when I want to create an object of this class I receive this error:
include(CronTab_Manager.php): failed to open stream: No such file or directory
Any suggestion will be appreciated.
Thanks in advance.
you can put your class file inside models folder or components folder.
if it is as extension then
'import'=>array(
'application.models.*',
'application.components.*',
'ext.cronTab.*',
),
Set path like this:
Yii::setPathOfAlias('cronTab','ext.CronTab_Manager');
In my main config i have:
'import' => array(
'application.models.*',
'application.components.*',
I read somewhere that Yii import only calls the relevant class when needed.
Wanted to know if it's true and if importing all the folder at once is good practice in Yii.
Thanks,
Danny
In the import call, when you pass in a folder like 'application.models.*', what Yii does, its add that path to the php include_path, so that when you call a class contained in that folder, if the Yii autoloader fails php looks for that class in the include path, thats fast.
If you include a file like 'application.models.FormModel', then Yii autoloader is aware of it and also loads the class on deman only.
you can find more information on the Yii guide: importing classes
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());
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.