Viewing New Page Gives Error 403

Hi,

I want to add a new page,so i have created a function in my master controller as below and created a goodbye page in views\master\goodbye.php.

Code added in Master Controller




public function actiongoodbye()

	{

		

		$this->render('goodbye');

			

	}



I am login with admin user, i can delete the records but when i open this page through url (index.php?r=master/goodbye.php)i am getting not authorized error. whereas if i paste the same code in sitecontroller and save the goodbye.php in views\site\goodbye.php page opens.

Error 403

You are not authorized to perform this action

Kindly help in this.

Thanks in advance

Modify your access rules in your controller to allow this action, for example, like this:-




		array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete','goodbye'),

				'users'=>array('@'),

			),




Hi Jimlam,

Wow it works. Thanks

I am achieving the below but getting error.

I have a table which is having a date column in it. I want to create a duplicate page of the cgridview (admin.php) but this page will have date sorted with today’s date.

I copied admin.php and renamed it to todaysdate.php, when viewed the page it is showing exception error

Can someone please help me to achive this.

Thanks in advance.

I understand you wish to have in the gridview only the data having today’s date. Am I right?

You can do column based filtering with the filter property:

http://www.yiiframework.com/doc/api/1.1/CGridView#filter-detail

HiJimlam,

I am still learning this application.

I will try the filter property, meanwhile can you please let me know if I copied admin.php and renamed the copied file to todaysdate.php & when viewed that page (todaysdate.php) why it is showing exception error.

is it that i am doing something wrong.

i want both the file admin.php which will show all the data and additional page todaysdate.php which will show only today’s date data.

Do you have any idea.

How are you callling todaysdate.php? Do you have an action created for it in your controller? Maybe it is again a problem of access rules.

In the admin.php which runs fine, don’t you have filter enabled? If you have, try to input something (if you have a column ‘name’ for example, input 1 letter found in one of the names in the name column) in the filter row (just below the headers of your table) and see if it works.

With the filter option, you do not have to create a copy of your admin page: you can filter on your columns data as you wish including today’s date.

HiJimlam,

I was getting model exception because i have not added the model attribute in actiontodaysdate in my controller,

Now after adding the below code i am able to view the page.

I want to sort the date with todays date in User_Next_Action field of todaysdate.php which is a datetime field.

I have added the code of todaysdate.php for your reference





public function actiontodaysdate()

	{

		$model=new Master('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Master']))

		$model->attributes=$_GET['Master'];

		$this->render('todaysdate',array(

			'model'=>$model,

		));

			

	}






public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view' ),

				'users'=>array('*'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update' ),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete', 'todaysdate'),

				'users'=>array('admin'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}



todaysdate.php




<?php

/* @var $this MasterController */

/* @var $model Master */


$this->breadcrumbs=array(

	'Masters'=>array('index'),

	'Manage',

);


$this->menu=array(

	array('label'=>'List Master', 'url'=>array('index')),

	array('label'=>'Create Master', 'url'=>array('create')),

);


Yii::app()->clientScript->registerScript('search', "

$('.search-button').click(function(){

	$('.search-form').toggle();

	return false;

});

$('.search-form form').submit(function(){

	$.fn.yiiGridView.update('master-grid', {

		data: $(this).serialize()

	});

	return false;

});

");

?>


<h1>Manage Masters</h1>


<p>

You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>

or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.

</p>


<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial('_search',array(

	'model'=>$model,

)); ?>

</div><!-- search-form -->


<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'master-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	

	

	'afterAjaxUpdate'=>"function(){jQuery('#Registration_Date').datepicker({'dateFormat': 'yy-mm-dd'})}",




	'columns'=>array(

		'Name',

		'Mobile',

		'Email',

		array( 

        'name' => 'Status', 

        'filter' => $model->getStatusOptions(), 

		),


		array('name' => 'Registration_Date', 'type' => 'raw',  'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array('model'=>$model, 'attribute'=>'Registration_Date', 'htmlOptions' => array('id' => 'Registration_Date'), 'options' => array('dateFormat' => 'yy-mm-dd')), true)),


		'User_Next_Action',

		'User_Remarks',

		

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>



todaysdate.php




<?php

/* @var $this MasterController */

/* @var $model Master */


$this->breadcrumbs=array(

	'Masters'=>array('index'),

	'Manage',

);


$this->menu=array(

	array('label'=>'List Master', 'url'=>array('index')),

	array('label'=>'Create Master', 'url'=>array('create')),

);


Yii::app()->clientScript->registerScript('search', "

$('.search-button').click(function(){

	$('.search-form').toggle();

	return false;

});

$('.search-form form').submit(function(){

	$.fn.yiiGridView.update('master-grid', {

		data: $(this).serialize()

	});

	return false;

});

");

?>


<h1>Manage Masters</h1>


<p>

You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>

or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.

</p>


<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial('_search',array(

	'model'=>$model,

)); ?>

</div><!-- search-form -->


<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'master-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	

	

	'afterAjaxUpdate'=>"function(){jQuery('#Registration_Date').datepicker({'dateFormat': 'yy-mm-dd'})}",




	'columns'=>array(

		'Name',

		'Mobile',

		'Email',

		array( 

        'name' => 'Status', 

        'filter' => $model->getStatusOptions(), 

		),


		array('name' => 'Registration_Date', 'type' => 'raw',  'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array('model'=>$model, 'attribute'=>'Registration_Date', 'htmlOptions' => array('id' => 'Registration_Date'), 'options' => array('dateFormat' => 'yy-mm-dd')), true)),


		'User_Next_Action',

		'User_Remarks',

		

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>



You can do the same thing with ‘user_next_action’ as you did with ‘Registration_Date’ and then choose todays’ date in datepicker filter. May be I am not quite getting your point

Hi Jimlam,

i want a link(todayspage.php) when clicking on that link it will sort the field of User_Next_Action with todays date (now function) and provide the data of current day.

Sorry Sanjay,

I misunderstood you. Modify your actiontodaysdate() in your controller like this:-





public function actiontodaysdate()

	{

		$model=new Master('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Master']))

		$model->attributes=$_GET['Master'];

 	        $model->date=date('d-m-Y');// add this line, note that you must change the date format to your format

		$this->render('todaysdate',array(

			'model'=>$model,

		));

			

	}




In fact, you don’t need to make a copy of the original actionAdmin but you can modify this original action (actionAdmin) like this:-





public function actionAdmin($dt=null)

	{

		$model=new Master('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Master']))

		$model->attributes=$_GET['Master'];

                if($dt != null)   

 	        $model->date=$dt; 

		$this->render('admin',array(

			'model'=>$model,

		));

			

	}




Hi Jimlam,

Thanks for your reply…

I will check and let you know…

Sorry,

A last sentence got cut off from my reply:

In your link where you called todaysdate, you pass today’s date as parameter for the action Admin.

Hi jimlam,

Sorry for my late reply,

actually i was busy in some other issues so not done the testing.

I have checked today and it worked perfectly.

Thanks…