Jump to content
Larry Ullman's Book Forums

Brent Knigge

Members
  • Posts

    17
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Brent Knigge

  1. Hello,

     

    I think this link to the documentation for loadMultiple might help.

     

    http://www.yiiframework.com/doc-2.0/yii-base-model.html#loadMultiple()-detail

     

    Maybe add the formName and see if that helps.

    if (FeuilleDeJourResponsable::loadMultiple($array_feuille_de_jour_responsable,Yii::$app->request->post(), 'FeuilleDeJourResponsable') )
    

    Also check the Post data to see what the form name is, and ensure that it matches with what you're expecting.

     

    Hope this helps,

     

    Brent.

  2. I can highly recommend getting yourself a program like Charles Web Proxy.  It is especially useful for helping to solve these issues because you can see everything that is being passed back and forth - especially when it comes to AJAX / CURL etc.

     

    Helped come to the same resolution you've had, and solved my puzzles in a matter of minutes instead of days.

     

    Hope that helps,

  3. Hi,

     

    The error message you are describing is a normal PHP error, not something specific to Yii.  You haven't given us the actual line number of where the error has occurred, and I can't see anything that is immediately obvious (except CActiveForm).

     

    The unexpected message usually means that the prior statement is incomplete.  I.e. missing semi-colons, braces etc.  I would be looking for that.  Here is an example (notice the missing semi-colon after 'brent').

     

    <?php
    
    
    $name = 'brent'
    $registrations = true;
    This is the output when I run it:
     
    Parse error: syntax error, unexpected '$registrations' (T_VARIABLE) in C:\programming\error1.php on line 4
    Also not sure if it is related, it appears you are mixing Yii1 and Yii2.  CActiveForm is part of Yii1.  This could be where you are experiencing a problem.
     
    regards,
     
    Brent
  4. Essentially yes, I believe that you would need to do that for each of your actions.  

     

    There are a couple of ways of doing this.  You can do the access control like you've mentioned, or you could use Yii::$app->user->isGuest inside each action method to determine whether the action can be performed.  

     

    You might be able to set up a 'default' access control in the config file.  Haven't looked into that part yet.

     

    Hope this helps,

     

    Brent

  5. Hi,

     

    I don't think there are any access controls for a model (otherwise I'm going to be confused myself).  There are 'rules', and scenarios in models and these dictate how an attribute is to be populated.  There are access control (with rules) in the controller that determine how certain actions can be accessed.

     

    Access Control has rules. You don't have one with out the other.  (kinda like Access control is a table, and rules are fields).

     

    Here is a basic access control that I built to try things out.

     

    So the only is for the action methods.  I.e. actionCreate, actionRbac2 etc

    Then I have the rules set up.

    The first rule is that only authenticated users (@)are allowed create and update action methods.  This is a simple case of access control.

    The second rule is using a role (set up as part of RBAC), and oddly enough I have this action method called rbac2 that it is allowed to access.  As part of my learning experience I found it easier to keep track of things when the 'role' matched the method that I wanted RBAC for (i.e. rbac2 role can access rbac2 action method.  Easy to test, look for error messages etc).

     

    'access' => [

                    'class' => \yii\filters\AccessControl::className(),

                    //Access control is only available on the following actions

                    'only' => ['create', 'update', 'rbac2],

                    'rules' => [

                            // deny all POST requests

                              [

                              'roles' => ['@],

                              //this rule is for these actions

                              'actions' => ['create', 'update'],

                              

                              'allow' => true,

                              //this is to be called if access is denied.  If not set, denyAccess() will be called    

                              'denyCallback' => function ($rule, $action) {

                                                     throw new \Exception('BK You are not allowed to access this page');

                                                            }

                             

                              ],

                              [

                               'allow' => true,

                               'roles' => ['rbac2],

                               'actions' => ['rbac2'],

                              ],       

                            // everything else is denied

                          ],

                       ],

     

    Hope this helps,

     

    Brent

  6. You could post your information here or send Larry an email directly.  The idea of having an ebook that is released in multiple stages is that the mistakes you find, can be corrected in the next release.

     

    Everyone benefits.

     

    Brent.

    • Upvote 1
  7. Hi Again,

     

    Looking at the code and the steps you've taken, I can now see where the issue is.

     

    In urlManager, the first rule that matches will be actioned.  When you look at this url

     

    ullman.local/page/testpage1 (As per Brent's suggestion)

     

    It will actually match this rule.

     

     

    '<controller:\w+>/<action:\w+>' => '<controller>/<action>',

     

    but it will also match this one

     

    'page/<view:\w+>'=>'site/page',

     

    So which ever rule you have first, is the one that will be actioned.  This is what is happening here, and Yii is trying to find a controller called page and an action called testpage1 - which neither exist.

     

    Move the 'page/<view:\w+>'=>'site/page', to the top of the list.  I.e the most restrictive rules should be listed first, followed by the general rules and then it will work.

     

    Larry's solution will work being placed at the end of the list because the url suggested won't match any of the existing general rules in place.

     

    I'm sorry, I should have seen this earlier.

     

    Cheers,

     

    Brent.

  8. hi,

     

    The directory needs to be this: 

     

    E:\xampp\htdocs\ullman\views\site\pages\testpage1.php

     

    Notice that it is pages not page.

     

    You still access through the same url as I mentioned before.  I.e. ullman.local/page/testpage1

    this link to the documentation explains that the default directory in use is pages unless otherwise specified. You reference thru page because that is what we have set up in the urlManager.

     

    P.S. I've been through the same learning curve with static pages as you, but once you get it you'll be wondering why it just didn't click in the first place.

  9. Hi,

     

    Thanks Larry I got myself a little bit confused looking at the 'about' page and figuring out the route.  Now that i have looked at a different static page (not part of site), I am okay (and feel a little silly).

     

    Okay first up, your actions method has the array elements error, captcha and page.  This is like having methods actionError, actionCaptcha and actionPage.  Except that instead of coding our own methods, we are pointing each one to a class to handle the particular action.  So when we call the action page it knows to use the ViewAction class to handle the action.

     

    Okay now for 'yii\web\ViewAction' the default directory is pages, so you should have this directory instead.

     

    E:\xampp\htdocs\ullman\views\site\pages\view\testpage1.php

     

    E:\xampp\htdocs\ullman\views\site\pages\testpage1.php

     

    Next we need to make sure that the routes are set up properly.  Add the following to your config file urlManager part.

    'page/<view:\w+>'=>'site/page',

    Okay the left hand side is what we are seeing in the URL.  The right hand side is the route.  So the proper navigation is

     

    ullman.local/page/testpage1

     

    will redirect to the site controller, page action and pass testpage1 to the class etc.

     

    That should be working now.

     

    Brent

  10. Hi,

     

    You need to modify the routes in the urlManager to work with static pages.

     

    here is what I have added

     

    'page/<view:\w+>'=>'site/page',
     
    This means I can navigate to http://localhost/yiistuff/site/aboutand the proper page shows up.  Here are some notes from my Action method that might help
     
               
     //I added this for displaying static pages...
                //now I can goto ...site/page?view=hello
                //if you want pretty urls, you can change in the urlManager like so.
                //'page/<view:\w+>'=>'site/page',
                //which means navigating ...site/page/hello
                
                //the directory where the hello.php resides is pages (this is the default).
                //you can change the directory by specifying the viewPrefix.
                'page' => [
                    'class' => 'yii\web\ViewAction',
                    //'viewPrefix' => 'pages2',
                ],

    Hope that helps,

     

    Brent

  11. Hello,

     

    You need to use the getDB method of the ActiveRecord class.  http://www.yiiframework.com/doc-2.0/yii-db-activerecord.html#getDb()-detail

     

    If you wanted your model code to switch between different DB, then I suppose you could set a public attribute in the model which would then could be returned from getDB.

     

    There is some more information here: http://stackoverflow.com/questions/27254540/yii-2-0-multiple-database-connection

     

    Hope that helps,

     

    brent 

  12. Hello,

     

    There are 2 types of authManager.  PhpAuthManager and DbAuthManager.  

     

    Without seeing your config file, I would guess that you are using PhpAuthManager - hence assigning the roles to the users.  DbAuthManager is where you would store the roles and credentials in a database which is what I think you want.

     

    Hope that helps,

     

    Brent

  13. Hope its not too late to chime in here.  There have been some good points raised in regards to file permissions, however you also need to look at the group and owner of your directories and files (which hasn't been mentioned yet).

     

    If your site was uploaded via ftp/scp etc to your home directory, and then copied using sudo to your /var/www folder, then chances are the files and folders are now owned by root.

     

    For apache to run your site, you need appropriate permissions (755 etc), but you also need the right owner and group.  Apache runs under www-data, so your files and folders should also be www-data.  To make this change for all folders and files in your website, use the following command.

    sudo chown -R www-data:www-data /var/www/myWebsite
    

    The -R means to recursivily to files and sub-directories etc.  I have changed the owner and group at the same time, however you can do them separately if necessary.

    sudo chown -R www-data /var/www/myWebsite
    sudo chgrp -R www-data /var/www/myWebsite
    
    • Upvote 1
×
×
  • Create New...