Here is my console.php which is same as main.php
return array(
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'name' => 'My Console Application',
// preloading 'log' component
'preload' => array('log'),
// autoloading model and component classes
'import' => array(
'application.models.*',
'application.components.*',
'application.extensions.*',
),
The web application has no problem access those functions. However, console application yields error
Fatal error: Call to undefined method Myfunction::get_all_recipients()
An discussion of this problem is also found at
https://github.com/yiisoft/yii/issues/2344
Also tried suggestions
Yii Command Line Does Not Autoload Models
but it still does not import model classes.
The second solution should work, but sometimes I use another approach. In the console command itself add the following:
Yii::import('application.models.YourModel');
or
Yii::import('application.models.Subfolder.YourModel');
if it's located in subfolder for example;
This should placed before your code is processed. This autoloads only models or classes that your need for current command.
Related
Sorry real new to yii, but where do i put the yii-booster 2.0 files?
I tried putting all the files into the extensions/bootstrap folder.
I then edited config/main.php and added this
'bootstrap' => array(
'class' => 'bootstrap.components.Bootstrap',
),
and
'preload'=>array(
'log',
// 'fontawesome',
'bootstrap',
),
and
'theme'=>'bootstrap',
where I have a theme in themes/bootstrap which I took from my previous installation of http://www.cniska.net/yii-bootstrap/
but I'm getting this error
Bootstrap and its behaviors do not have a method or closure named "register".
from the theme you got from http://www.cniska.net/yii-bootstrap/
try removing this in themes/bootstrap/views/layout/main.php
Yii::app()->bootstrap->register();
Is there a way to configure Yii such that it will no longer load any Javascript out of the Assets folder?
Make your own AssetManager or extend current
protected/components/DummyAssetManager.php:
class DummyAssetManager extends CApplicationComponent {
public function publish(){}
}
add into components array in
protected/config/main.php:
'assetManager'=>array(
'class'=>'DummyAssetManager',
),
You should consult the manual for a detailed description of
the assetManager options
I think you can try following option in your config/main.php
'components' => array(
'assetManager' => array(
'linkAssets' => true,
),
),
This will make asset files symbolic links to your original js/css sources. See linkAssets for more details on it.
If your PHP<5.3, or the OS it's running on doesn't support symbolic links, you won't be able to use 'linkAssets' option, in this case you can try:
'components' => array(
'assetManager' => array(
'forceCopy' => true,
),
),
This should update asset folder on every request. These two options are usually used during development process (btw, you can't use both) and should be removed from production.
PS: if you're sure that you haven't explicitly enabled ckeditor somewhere in your code and you're confident about your assetmanager calls throughout the code, check your layout and page for widgets that require this CKeditor, as Yii can't preload 'stuff' just randomly, it can be triggered by some preloaded component/extension or yii widget.
I just started looking about Phalcon this week, I'm trying to create a multiple module application with the dev tools.
The result of running phalcon project <name> multiple only creates one module ('frontend') and it works fine. However, when I add a second module (by copying the frontend one and changing the namespace to \Backend , I couldn't get to the Backend\IndexController class.
After reading the doc page about mutiple module applications and looking at the samples (https://github.com/phalcon/mvc/tree/master/multiple and https://github.com/phalcon/mvc/tree/master/multiple-volt) and an old question on the Google group (sorry, can't post more than 2 links since I'm new on StackOverflow), I've ended commenting this this line on the services.php file:
$router->setDefaultNamespace("MyL\Frontend\Controllers"); //project name is MyL
and adding the following on the setServices of my backend/Module.php file:
$di->set('dispatcher', function() {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("MyL\Backend\Controllers");
return $dispatcher;
});
and the something similar on the frontend/Module.php
It works with these modifications, but my question is: is this the best way to do it, or is there a better way?
Thanks in advance!
You need to register your modules in your app like so:
$app = new \Phalcon\Mvc\Application();
$app->registerModules(
[
'frontend' => [
'className' => 'MyL\Frontend\Controllers',
'path' => '../apps/frontend/Module.php'
],
'backend' => [
'className' => 'MyL\Backend\Controllers',
'path' => '../apps/backend/Module.php'
],
]
);
Make sure that you have the Module.php ready also for each module
Here is a simple way to split frontend and backend in Phalcon project without modules:
https://github.com/borzov/phalcon-templates
i have implemented module based login from
here
by update 2 method and it works fine for me .
Now there is need to access this module as different role,
i implement user level access to this module as described here
i add LevelLookUp class to EWebUser.
when i try to login now a CException
"CWebUser and its behaviors do not have a method or closure named "isAdmin". "
displayed.
it means module is still using CWebUser, but i create my own EWebUser and place it to module/components/EWebUser.php
and code in module config file init method
$this->setImport(array(
'bgadmin.models.*',
'bgadmin.components.*',
));
$this->setComponents(
array(
'errorHandler' => array(
'errorAction' => 'bgadmin/default/error'),
'user' => array(
//'class' => 'CWebUser',
'class' => 'EWebUser',
'loginUrl' => Yii::app()->createUrl('bgadmin/default/index'),
)
));
Problem-
1.where to place LevelLookUp class
2.why module is still using CWebuser instead of EWebUser ?
RETRY------------
when i change
$this->setComponents(
to
Yii::app()->setComponents(
then it access the EwebUser but not the loginurl as i logged in but now 2 PROBLEMS
1.'expression'=>'Yii::app()->user->isAdmin()' not works but in class EwebUser it return flase.
2.when logout give error "Property "BgadminModule.user" is not defined. "
logout code is
Yii::app()->user->logout(false);
$this->redirect(Yii::app()->getModule('bgadmin')->user->loginUrl);
in previous case logout was working fine.
Please help me .
When you call $this->setComponents() in a module then actually you set a new component for
you module so to access user component for your module you have to write the following
statement
Yii::app()->getModule('bgadmin')->user->isAdmin() or
Yii::app()->getModule('bgadmin')->user->id
for logout in your admin module you have call it in this way
Yii::app()->user->logout(false);
This will work fine if you are using $this->setComponents() method.
If 'class' => 'EWebUser', doesn't call your class then try to change path as
'class' => 'application.modules.bgadmin.components.EWebUser',
This should work for your bgadmin module
I need to use a file manager in pop up which comes on a button click. I am using Yii extension elfinder. I am finding it hard to understand the way of using it. I downloaded the code from bitbucket, put it inside my application in the folder extension. I try to test it using new controller, named it elfcontroller and put the following code (got from the website)
class ElfinderController extends CController
{
public function actions()
{
return array(
'connector' => array(
'class' => 'ext.elFinder.ElFinderConnectorAction',
'settings' => array(
'root' => Yii::getPathOfAlias('webroot') . '/uploads/',
'URL' => Yii::app()->baseUrl . '/uploads/',
'rootAlias' => 'Home',
'mimeDetect' => 'none'
)
),
);
}
}
and i created one more function for rendering the index page(i want the file manager to be in this page)
in the view i wrote the following code
$model = new xxxmodel();
$this->widget('ext.elFinder.ElFinderWidget', array(
'model' => $model,
'attribute' => 'serverFile',
'connectorRoute' => 'admin/elfinder/connector',
)
);
and i included a div for containing it
But i am getting the following error
Alias "ext.elFinder.ElFinderWidget" is invalid. Make sure it points to an existing PHP file and the file is readable.
i tried to include alias in config/main.php
I know i am messing some where with the folder structure
here is the path i am using the extension
C:\xampp\htdocs\project\protected\extensions\ext.elfinder
I returned empty after google searches, can any one please explain me how to use this extension to place the code exactly where it is needed to be?
In general the extensions folder already has the ext alias, so you don't need to set an alias for it.
Then the extension itself should be placed in the extensions folder, somewhat like : project/extensions/extension-name/ . In your case it should be: project\extensions\elFinder , and keep the rest of your code same, i.e continue referring to extension like:
ext.elFinder.ElFinderWidget