Yii: The system is unable to find the requested action "select" - yii

what i am doing is trying using the yii select2 extension to create a searchable dropdown list. i have downloaded the extension from this link and following it "http://www.yiiframework.com/extension/select2/".
i have put the unzipped file(which is select2) in protected/extensions and i have then created a php file in "protected/views/site/select.php" in which i pasted the code below and when i try to run it via "webapp/index.php/site/login" it gives this error "
Error 404
The system is unable to find the requested action "select"." Please help me with this, thankyou..!!
//code in select.php(protected/views/site/select.php)
$tags=array('Satu','Dua','Tiga');
echo CHtml::textField('test','',array('id'=>'test'));
$this->widget('ext.select2.ESelect2',array(
'selector'=>'#test',
'options'=>array(
'tags'=>$tags,
),
));

It seems that you have make the view file (protected/views/site/select.php) but you don't have created the corresponding action.
Add in SiteController:
public function accessRules() {
//You can modify accordingly but you have to insert select to allowable actions
return array(
array('allow', // allow all users to perform 'index', 'contact' and 'select' actions
'actions'=>array('index', 'contact', 'select'),
'users'=>array('*'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
public function actionSelect() {
$this->render('select');
}

Related

Alias "ext.components.MyClass" is invalid. Make sure it points to an existing PHP file and the file is readable

i am new in yii framework. currently i am using yii 1.1.
now i want to create custom components and we can say than create global function which is use anywhere in the application.
According to this url 'http://www.yiiframework.com/wiki/727/updated-how-to-create-call-custom-global-function-in-whole-application/'
i am follow all steps according to above url
but i have occur a error
Alias "ext.components.MyClass" is invalid. Make sure it points to an existing PHP file and the file is readable.
MyClass.php in the components folder
class MyClass extends CApplicationComponent {
public function get_my_info() {
$value = '1';
return $value;
}
}
Declare in the config folder
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'myClass' => array(
'class' => 'ext.components.MyClass',
),
And use in the view file
<?php
$myInfo = Yii::app()->myClass->get_my_info();
echo $myInfo;
?>
Have you put the file in correct component directory?. As per your alias the path should be /protected/extensions/components/MyClass.php
Write full path like application.modules.setting.components.*

Yii2 Captcha dosent render and show raw data image

Captcha in backend is configured and has worked.
But with same configuration does not work on front-end and show raw image data, like in the picture.
Access roles are correct and captcha action does not have any additional config.
PHP GD is already active in my host
Yii2 Captcha show RAW data
Two things you might want to check.
First, did you override the actions() method in your controller class? You'll need to add the following:
class YourController extends Controller
{
public function actions()
{
return array(
'captcha' => array(
'class' => 'CCaptchaAction',
'backColor' => 0xFFFFFF,
),
);
}
}
If you did that and it still doesn't work, check your controller access. When you are overwritten accessRules(), you need to make the captcha action available for everyone, like this:
class YourController extends Controller
{
public function accessRules() {
return array('allow', 'actions' => array('captcha'), 'users' => array('*'));
}
}
Hope this helps !.
ob_clean();
please try before you show captcha or any other suitable place.

can't display error page layouts in yii

I am able to render my specified error pages in my modules, but I can't get error layouts outside of my modules.
It's quite strange, in my main config I have:
'errorHandler'=>array(
'errorAction'=> '//site/error',
),
I tried to see if it is pointed to the right file by changing it to //site/contact, and see if it renders the contact page if error. And it does show.
So the path is correct, then how come it's not showing the error page? It shows the default white page with exception error. The exception page is what im expecting, but how it's formatted is not.
public function actionError()
{
$this->layout = '/layouts/main';
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', array('error'=>$error));
}
}
Your user role doesn't have rights to access actionError() in controller.
In your site controller, You can see a function called public function accessRules().
Check error is added for some user role, or it's for admin only.
If error not found, then add it for user roles.
Example:
public function accessRules()
{
return array(
array('allow',
'actions' => array('index', 'view', 'error'),
'users' => array('#')
),
..
..
..
}
You need to create a errorXXX in views/system. The XXX stand for the error code, in this case most likely a 403. For more information see this page on the Yii site.

Using Elfinder extension in Yii

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

Chtml link failing

I try to link from the site controller to another controller action using the Chtml::link, but it keeps redirecting me to the site/login page.
This code I have in the login view rendered from the site controller looks something like this:
<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'Aboutinfo'));
.
.
<?php echo CHtml::link('Learn more here', array('site/page','view'=>'about')); ?>
.
.
echo CHtml::link('Link label', array('othercontroller/action'));?>
.
.
<?php $this->endWidget();?>
Thanks for any suggestions/corrections for what I might be doing wrong
Check the accessRules function in the controller you are trying to link to. You should see something like this:
public function accessRules()
{
return array(
array('allow',
'actions'=>array('index'),
'users'=>array('*'),
),
array('allow',
'actions'=>array('browse', 'add'),
'users'=>array('#'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
The 'users'=>array('*') means allow any user to access the action. The line 'users'=>array('#') means allow only logged in users to access the action (browse & add in the above case).
Make sure your rule settings are correct. I suspect the actions you are linking to have accessRules setup that require users to be logged in to view the page. If the controller detects that the user is not logged in, it will redirect user to the login page.