我想显示CGridView组件与所有记录作为其相关更新页面的链接.
我希望每行末尾都有编辑按钮的功能,应用于整行.
如果我单击特定行的任何位置,它将分别将我重定向到其更新屏幕.
在Yii的CGridView中有可能吗?
我想知道用户是否是使用Yii :: app() - > user-> isGuest的访客,但我收到以下通知:
Undefined property: CWebApplication::$user
Run Code Online (Sandbox Code Playgroud)
显然组件用户尚未在应用程序中定义,我想知道原因.
我试图通过检查组件是否可用
if(isset(Yii::app()->user))
Run Code Online (Sandbox Code Playgroud)
然而它失败了¿即使没有定义Yii :: app() - > user,我如何检查用户是否是访客?¿使用isGuest时我是否应该注意到这一点?
编辑:我将error_reporting指令更改为"E_ALL&~E_NOTICE&~E_DEPRECATED&~E_STRICT"我需要继续前进.现在我得到了这个致命的错误:
致命错误:在第530行的home/mario/projects/ciudad_wiki/yii/framework/web/auth/CWebUser.php中的非对象上调用成员函数getId()
我目前在使用URL管理器和/或apache mod_rewrite时遇到问题,或者完全是其他问题.
如果将showScriptName设置为false,则导航到domain.com/login,domain.com/logout,domain.com/site/login等地址的行为方式都相同.它只显示主站点/索引,就好像我要导航到domain.com/eeofjew9j8jfdedfmewf(jibberish).
也许这是我的Yii设置的问题?以下是那些(对不起):
'components'=>array(
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'login'=>'site/login',
'logout'=>'site/logout',
'register'=>'users/register'
),
,...
Run Code Online (Sandbox Code Playgroud)
以下是我在www root中设置.htaccess的方法:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
Run Code Online (Sandbox Code Playgroud)
我正在使用VPS服务器,因此我具有root访问权限,可以对apache进行任何更改.我检查了我的phpinfo并且mod_rewrite正在运行并启用.在我的apache配置中,我有我的www目录:
AllowOverride All
Options Indexes FollowSymLinks MultiViews
Order allow,deny
Allow from all
Run Code Online (Sandbox Code Playgroud)
我已经通过3个不同的主机(godaddy,dreamhost和锂主机)在这个问题上摸不着头脑,所以我认为这是我的问题.既然我有VPS,我希望我能最终找出问题并解决它.
我仍然在Yii 1.xx中编写CDbCriteria的全部功能 - 我有一个相当复杂的SQL查询,我希望使用CDbCriteria格式转换为模型中的查询(如果可以使用更复杂的查询.
我最初尝试这个..
$criteria = new CDbCriteria;
$criteria->select = array(
't.classroom_id, title',
'COALESCE(COUNT(DISTINCT r.redeemed_code_id),0) AS totalRewards',
'COALESCE(COUNT(DISTINCT ocm.user_id),0) AS totalStudents',
'COALESCE(SUM(r.points),0) AS totalPoints'
);
Run Code Online (Sandbox Code Playgroud)
任何人都可以使用以下查询建议最好的方法吗?建议任何建议,谢谢..
SELECT
t.classroom_id,
title,
COALESCE ( r.classRewards, 0 ) AS totalRewards,
COALESCE ( r.classPoints, 0) AS totalPoints,
COALESCE ( COUNT(DISTINCT ocm.user_id), 0 ) AS totalStudents
FROM
organisation_classrooms t
LEFT JOIN ( select crc.classroom_id,
COUNT( DISTINCT crc.redeemed_code_id ) AS classRewards,
SUM( crc.points ) as classPoints
from classroom_redeemed_codes crc
JOIN organisation_classrooms t
ON crc.classroom_id = t.classroom_id …Run Code Online (Sandbox Code Playgroud) 这是我的RESTful控制器的样子.
<?php
namespace backend\controllers;
use yii\rest\Controller;
use yii;
use yii\web\Response;
use yii\helpers\ArrayHelper;
class UserController extends \yii\rest\ActiveController
{
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
[
'class' => 'yii\filters\ContentNegotiator',
'only' => ['view', 'index'], // in a controller
// if in a module, use the following IDs for user actions
// 'only' => ['user/view', 'user/index']
'formats' => [
'application/json' => Response::FORMAT_JSON,
],
'languages' => [
'en',
'de',
],
],
[
'class' => \yii\filters\Cors::className(),
'cors' => [
'Origin' => ['*'],
'Access-Control-Request-Method' => ['GET', …Run Code Online (Sandbox Code Playgroud)UserMasterController代码:
public function actionUpdate($id){
$model=$this->loadModel($id);
if(isset($_POST['UserMaster'])){
$model->attributes=$_POST['UserMaster'];
$model->attributes['emailsent'] = 'N';
if($model->save())
$this->redirect(array('admin'));
}
$this->render('update',array(
'model'=>$model,
));
}
Run Code Online (Sandbox Code Playgroud)
给我一个错误的行是: $model->attributes['emailsent'] = 'N';
错误:间接修改过载属性
UserMaster::$attributes无效
如何更改属性值?我只是想将其设置为'Y'或者'N'按条件
对不起,如果我使用错误的关键字.由于错误的关键字,我可能没有得到足够的信息.
我们通过这种方式在Yii中创建小部件:
class streamList extends CWidget {
//do some stuff
}
Run Code Online (Sandbox Code Playgroud)
此外,我们在任何地方使用此小部件
$this->widget("application.components.widget.streamList");
Run Code Online (Sandbox Code Playgroud)
我们如何以接受参数的方式编写窗口小部件
$this->widget("application.components.widget.streamList",array('title'=>'Posts');
Run Code Online (Sandbox Code Playgroud)
我用Google搜索但没有解决.请帮助,谢谢.
编辑日志:
另外,我们如何将默认参数值定义为'titile'?我试过了public $title = Shk::getTitle(),但没办法.
好吧,PHP时代.
我的客户希望我使用Yii2作为他的项目的框架.
我把它搞定了.没问题.我通过作曲家使用了高级模板.
将我的Web根目录设置为/ frontend/web等.
现在,我想使用这种网址格式
website.com/messages/或website.com/messages/tom ...等
现在的方式是设置显示website.com/index.php?r=messages/index ...
我找到了这个文件......
https://github.com/yiisoft/yii2/blob/master/docs/guide/url.md
但我似乎无法直截了当.
这是我的步骤......
我配置我的apache服务器指向/ usr/www/payroll/frontend/web /
我在我的web文件夹中添加了一个包含此内容的.htaccess文件.
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
Run Code Online (Sandbox Code Playgroud)
我还在路线中添加了组件'urlManager'.它似乎捕获请求并修改它.
'components'=>[
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => 'false'
],
],
Run Code Online (Sandbox Code Playgroud)
例如,如果我输入website.com,您可以看到它将url/site/index添加到url.(如果没有激活url组件,只需添加/index.php?site/index)
所以,显然有一个修改到url(通过UrlManager),但我得到404错误
我这里的想法已经不多了.我是Php,Apache和Yii2的新手.任何帮助,非常感谢.
谢谢
我需要创建新用户.我想在DB中将密码保存为哈希格式.但我失败了好几次.
这是我的代码:
public function actionCreate()
{
$model = new User();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Run Code Online (Sandbox Code Playgroud)
public function validatePassword($password)
{
return Security::validatePassword($password, $this->password_hash);
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public function setPassword($password)
{
$this->password_hash = Security::generatePasswordHash($password);
}
Run Code Online (Sandbox Code Playgroud)
public function rules()
{
return [
[['c_authkey', 'inserttime'], 'required'],
[['c_branch', …Run Code Online (Sandbox Code Playgroud) 我想扩展类yii\web\Response.所以我在文件夹组件中创建了一个新的类Response ,我尝试覆盖send方法.
namespace app\components;
use Yii;
class Response extends \yii\web\Response{
public function init(){
parent::init();
}
/**
* Sends the response to the client.
*/
public function send()
{ ...
Run Code Online (Sandbox Code Playgroud)
最后,我尝试通过在配置中导入它来导入我的新Response-Class.
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'import' => [
'class' => 'app\components\Response',
],
Run Code Online (Sandbox Code Playgroud)
为什么它不会像这样工作?
yii-components ×10
yii ×8
yii2 ×4
php ×3
.htaccess ×1
apache ×1
api ×1
controller ×1
frameworks ×1
gridview ×1
mysql ×1
rest ×1