我有一个现场客户代码.如果列表框的值为staff,则将禁用它,如果列表框值为admin,则将启用它.如果是admin,则需要customercode.但是如果是员工,则会禁用客户代码,并且不必应用任何规则.
怎么做?
在我正在创建的yii网站中,我有一个带有网址的页面,该网页以http://localhost/administrator/restaurant/list
表格格式显示餐馆列表以及删除按钮.删除按钮指向http://localhost/administrator/restaurant/delete/<id>.
在actionDelete我的控制器如下:
public function actionDelete(){
$model = Restaurants::model()->findByAttributes(
array(
'id'=>$_GET['id'],
'clientId'=>Yii::app()->user->clientId
));
$model->delete();
Yii::app()->user->setFlash('success',Yii::t('error','Restaurant has been deleted successfully'));
$this->redirect('restaurant/list',true);
}
Run Code Online (Sandbox Code Playgroud)
但是在单击"删除"按钮时,该行将从数据库中成功删除,但不是重定向到http://localhost/administrator/restaurant/list页面,而是重定向到http://localhost/administrator/restaurant/delete/restaurant/list并显示错误.我实现重定向功能的方式有问题吗?
我有以下示例代码:
$dataProvider = new CActiveDataProvider('firstTable',
array('criteria' => array(
'select' => 't.firstfield,secondTable.secondfield',
'join' => 'join secondTable on secondTable.id=t.secondTable_id',
),
'pagination' => array(
'pageSize' => 10,
),
));
$results=$dataProvider->getData();
Run Code Online (Sandbox Code Playgroud)
运行上面的代码后,firstField(来自model表 - firstTable)在对象中可用,但secondField(来自连接表 - secondTable)则不可用.
任何人都可以提供有关代码错误或"选择"选项没有获取第二个字段的帮助吗?
我正在使用yii php中的TCPDF库为发票生成pdf文档.在地址数据之后,有一部分带有购买物品清单.该列表具有可变长度,这使得难以预测下一部分将呈现的位置.最后有一部分付款,税款,运费等.
我想知道如何使最后一部分牢不可破.所以它完全在第一页或完全在第二页.
那甚至可行吗?
如果有帮助,这里是相关部分的代码:
$pdf->SetFont("helvetica", "", 9);
$pdf->Cell(4,0,'Versandart','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,"$model->versandart",'TBLR',0,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "", 6);
$pdf->Cell(5,0.4,'Hiermit bestätige ich den Auftrag','TLR',1,'R',0,'',0, 0,'','T');
$pdf->SetFont("helvetica", "", 9);
$pdf->Cell(4,0,'Frachtpreis','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,"$model->versandpreis €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->Cell(5,0,'','LR',1,'R',0,'',0, 0,'','T');
$pdf->Cell(4,0,'Nachnahmegeb.','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,"$model->nachnahme €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->Cell(5,0,'','LR',1,'R',0,'',0, 0,'','T');
$pdf->Cell(4,0,'SPV-Versicherung','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,"$model->versicherung €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "B", 6);
$pdf->Cell(5,0.4,'Ort, Datum, Unterschrift','BLR',1,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "", 9);
$pdf->Cell(4,0,'Nettobetrag','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,$totalSum-($model->vat/100)*$totalSum." €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "", 6);
$pdf->Cell(5,0.4,'Ich erkenne die AGB in der Homepage','TLR',1,'R',0,'',0, 0,'','T');
$pdf->SetFont("helvetica", "", 9);
$pdf->Cell(4,0,"incl. $model->vat% MwSt.",'TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,($model->vat/100)*$totalSum." €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", …Run Code Online (Sandbox Code Playgroud) public function actionCheckout()
{
echo "Hello World!";
}
Run Code Online (Sandbox Code Playgroud)
我刚刚在控制器中创建了这个非常简单的代码但是当我尝试在我的URL中浏览它时它会向我显示以下错误:

即使我目前以管理员身份登录,但仍然无法访问非常简单的代码.
我将发布CRUD生成的accessRules,我不知道这是否相互关联,但是当我尝试删除此行时,我已经可以访问该页面了.
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'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
Run Code Online (Sandbox Code Playgroud)
如果您可以看到在该代码上没有声明结帐,那么无关紧要.
您认为/是什么原因?非常感谢您的帮助和奖励!
谢谢!:)
根据这个链接,我几乎设法实现了结构.但路径别名让我很困惑.有人可以解释我如何实现这一目标.
http://www.yiiframework.com/wiki/155/the-directory-structure-of-the-yii-project-site/#hh5
我希望我的控制器在前端从公共文件夹访问这些模型.
谢谢
我正在使用此模型代码删除记录.
public function actionDelete($id)
{
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
Run Code Online (Sandbox Code Playgroud)
包含此记录的表与其他表具有一对多关系,具有删除限制约束.
因此,当删除子表中具有相关记录的记录时,它会抛出异常
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`bzuexamsystem`.`campus`, CONSTRAINT `fk_Campus_City` FOREIGN KEY (`CityID`) REFERENCES `city` (`CityID`) ON UPDATE CASCADE). The SQL statement executed was: DELETE FROM `city` WHERE `city`.`CityID`=1
Run Code Online (Sandbox Code Playgroud)
是否有某种方式显示用户友好的错误消息.谢谢
我有一个写代码来显示一个图像列的结果.不知怎的,它给了我错误
我写了这样的代码.
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'photo-grid',
'dataProvider' => $model->search(),
//'filter' => $model,
'columns' => array(
'id',
array(
'name'=>'user_id',
'value'=>'GxHtml::valueEx($data->user)',
'filter'=>GxHtml::listDataEx(User::model()->findAllAttributes(null, true)),
),
array(
'name'=>'regulation_id',
'value'=>'GxHtml::valueEx($data->regulation)',
'filter'=>GxHtml::listDataEx(Regulation::model()->findAllAttributes(null, true)),
),
//'photo_img',
array(
'name' => 'Photo Img',
'type' => 'raw',
'value' => CHtml::image(Yii::app()->controller->createUrl('photo/loadImage', array('id'=>$model->id)),"",array('width'=>50, 'height'=>50)),
),
array(
'class' => 'CButtonColumn',
),
),
Run Code Online (Sandbox Code Playgroud)
)); ?>
任何人都可以帮我如何在CGridView中显示图像?
如何配置我的小部件,他显示了屏幕上显示的结果数量?例如在标准的CGridview分页中(显示1到10的4087 *)
<?php $this->widget('common.ext.bootstrap.widgets.TbGridView', array(
'id'=>'search-by-name-grid',
'type' => 'striped',
'dataProvider'=>$dataProvider,
'template'=>'{items}{pager}',
'enablePagination' => true,
'columns'=>array(
Run Code Online (Sandbox Code Playgroud) 使用Yii Framework,如何在Controller中访问模型常量?
Model.php
...
const STATUS_ACTIVE=1;
...
Run Code Online (Sandbox Code Playgroud)
Controller.php这样
...
$criteria->condition = 'status='.self::STATUS_ACTIVE;
...
Run Code Online (Sandbox Code Playgroud)
错误:
Fatal error: Undefined class constant 'STATUS_ACTIVE' in ... on line X
Run Code Online (Sandbox Code Playgroud)