Jump to content
Larry Ullman's Book Forums

Brent Knigge

  • Posts

  • Joined

  • Last visited

  • Days Won


Brent Knigge last won the day on April 18 2016

Brent Knigge had the most liked content!

Brent Knigge's Achievements


Newbie (1/14)



  1. Have a look at Charles Proxy. I use this and it helps an awful lot, especially with AJAX stuff. You'll see everything going back and forth between your browser and server. The purpose of using this with your problem is to identify the POST variables and form names that are sent from your browser etc.
  2. 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.
  3. Hi, There is a property called name in app. Here is a link to the documentation for $app property. http://www.yiiframework.com/doc-2.0/yii-web-application.html use a program like notepad++ that can recursively search sub-folders for Yii::$app->name and see what shows up. You'll get an idea of how it might be used. Hope that helps, Brent.
  4. 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,
  5. 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
  6. 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
  7. Hi, The code sample I have is for Yii2. thanks, Brent
  8. 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
  9. 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.
  10. 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.
  11. 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.
  12. 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
  13. Hi, yiistuff is just an alias that I created in Apache. I have several (yiistuff1, yiistuff2 etc) set up that helps mimic what i would have on a server. Try experimenting with the url that you are using. You need to remove the view and probably page as well. so that you have ullman.local/site/about That should work. Brent
  14. 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
  15. 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
  • Create New...