Hi,
Can you give more explanations please. I want a system using a ‘minimal’ RBAC.
Wich user system are you using ?
Kinds Regards,
Ydakilux
Hi,
Can you give more explanations please. I want a system using a ‘minimal’ RBAC.
Wich user system are you using ?
Kinds Regards,
Ydakilux
Trying to use this code but I get
Setting unknown property: yii\widgets\ActiveForm::beforeSubmit
Actually I want to make a modal form (lets say Addresses) for create/edit inside of another one (lets say Person) in editing mode. Do you have any solution for that?
Check this topic. It’s worked fine for me.
I’ve checked again topic and yes, it’s not working. I totally forgot that my code is different, but it was based on this topic.
Here’s main difference, beforeSubmit is in JS:
$('body').on('click','.modalButton', function (){
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'));
});
function submitForm(id) {
// get the form id and set the event handler
$('form#' + id).on('beforeSubmit', function(e) {
var form = $(this);
$.ajax({
type: "POST",
url: form.attr("action"),
data: new FormData(form['context']),
processData: false,
contentType: false
})
.done(function(result) {
form.parent().html(result['message']);
$.pjax.reload({container:'#pjax_container'});
})
.fail(function() {
console.log("server error");
});
return false;
}).on('submit', function(e){
e.preventDefault();
});}
I hope it’ll explain the idea.
UPD:
And, of course, don’t forget to register JS:
<? $this->registerJs("submitForm('my-form');");?>
Hi ORey,
I have tried this out, but it show me error “Class ‘yii\web\AccessRule’ not found” .
fyi, I am using advanced template of Yii2.
But even I did not override AccessRule class and ruleConfig array, it seems work well too with my default roles code below:
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['admin', 'student'],
],
[
'allow' => true,
'actions' => ['logout'],
'roles' => ['@'],
],
],
],
];
}
I have added the component below in common/config/main.php
'authManager' => [
'class' => 'yii\rbac\DbManager',
'defaultRoles' => ['admin','student'],
],
May kindly advise is it somewhere already has improved the AccessRule so that I no need to override AccessRule?
Or is it the ‘defaultRoles’ in authManager array that work it out?
I am just wondering. : D
Thanks.
Still lot people using svn as well… i am one of it
Thats it? How does the User get the role of ‘moderator’ or ‘admin’ ?
Your user Model needs a ‘role’ attribute. In the default Yii advanced template, it already exists. Open common/models/User.php and check for the ROLE_USER constant. You can create more roles there, using the example provided by Orey.
Hi I get this Error:
Calling unknown method: yii\db\ActiveQuery::filtered()
What am I doing wrong?
I have tried this code, But, I get an error: Calling unknown method: yii\db\ActiveQuery::filtered()
What am I doing wrong?
Very useful, you are great.
fixed closing tag <script> should be </script>
Hi ORey,
This is indeed very cool except… it doesn’t work for me.
I checked documentation and apparently the asArray() function can only take one argument (boolean). I tried to give it an array as argument (list of columns), but the result doesn’t change. Am I missing something?
Here is my code:
In my view (for testing):
$ships = Ship::find()->asArray(['id','name'])->all();
foreach($ships as $ship)
{
echo '<pre>';
var_dump($ship);
echo '</pre>';
}
My Ship model has the following:
class Ship extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'ship';
}
public function fields()
{
return [
'id',
'abreviation',
'name',
'deleted',
'par_level',
'company_id',
'supervisor_id',
'class_id',
// The following are the extra fields
'company','class','shipClass','supervisor','colorByDate','latestSubmitShortDate'];
}
The result of the first item is:
array (size=10)
'id' => string '0' (length=1)
'abreviation' => string 'XX' (length=2)
'name' => string '<Ship> Of The Seas' (length=18)
'deleted' => string '0' (length=1)
'par_level' => string '0' (length=1)
'company_id' => string '1' (length=1)
'supervisor_id' => string '2' (length=1)
'class_id' => string '1' (length=1)
'created_at' => string '1426685104' (length=10)
'updated_at' => string '1426685104' (length=10)
I also tried to add the extra fields as you recommended in a separate function called extraFields(). But… it’s disregarded as well.
What am I doing wrong? Did the Yii2 code change? I’m using latest Yii v.2.0.6
Thanks a bunch!
Marian