Yii Problems With The Testdrive Example - yii

I'm trying to create my first Yii application, step by step, with the testdrive example but I meet some problems.
When I try to create a new user, I obtain an error CException:
UserController cannot find the requested view "_form".

If I understand you correctly, you've created a protected/controller/UserController.php.
From the sounds of it, somewhere in that code you have a call to render (or partialRender), that looks something like this:
$this->render('_form');
For this to work, you'll need a corresponding view file. Views should go in protected/views/<controllerName> and should be files that correspond to the view name you use. In your case, you'll need a protected/views/User/_form.php.

Related

DNN 7 Custom Profile Property with database validation

I'm using DotNetNuke 7 for my CMS. I created a custom profile property for zip codes. Does anyone know how to add custom validation for the data entry before allowing the user to register.
Thanks
I don't think DNN allows this in custom properties, you'll likely need to wire something up yourself to make this happen. You might be able to add some custom jquery to the registration page that does some webservice calls to check and validate a property, but I haven't tried that before so it would probably be a lot of trial and error until you get it working right.
Click on the pencil next to the property you created if its only one zip code then in the valid expression area put the zipcode ex:08109 of you wanted to have it at two zipcodes lets say 08109 and 08110 then you could use a validation expression something like this:
^[0]{1}[8]{1}[1]{1}[0-1]{1}[0-9]{1}$

Rails create static page from dynamic page

This seems like it should not be that hard but I am trying to figure out how to create a 'snapshot' or 'locked' view from one on my views. This view currently is dynamic but I want to lock it so that any changes I make will not propagate until I want them too.
This would be a front facing page that should not get updated until I choose to update it such as by timestamping a field like updated_lock or something to that effect.
Any ideas?
Thanks,
BR
You might try caches_action in your controller. It will create the static version and save it. You could either create it in dev and checkin, or have it generated in production. You'd need to fine a way to delete it in production if it's not checked in. Requires caching to be turned on.
If you are OK with checking it in - you can always save from the browser.
Basically - if there is a file in public at the same location as the view, it will be served instead of the dynamic one.

Using specific controller in layout - CakePHP

I'm newbie in CakePHP and I have a few questions.
I'm trying to set up my first CakePHP website, and I want to display menu with links in my layout. I've created model called MenuItem, then I've created controller "MenuItemsController" and then a function show. When I access /menuitems/show/ all my links are displayed. So here's the problem. I want do call this controller in my layout so links will be visible on every subpage. First question is how to call this controller, and second how will output look like ? Do I have to create view for this cotroller if I don't want to use /menuitems/show/ or it's okay to set controller to output just array of data ?
Thank you!
First question is how to call this controller, and second how will output look like ?
Use requestAction() to request the data from the view OR better, set it based on the page you're on in your AppController::beforeFfilter() method.
In your layout simply use an element $this->element('menu'); and use the set data in it or, if you go for requestAction() do this call inside the element, you can even cache the element.
Read the links to the CakePHP book in the text, the book contains example code as well.

How to access a view once you have generated it with GII (via YII)?

I've managed to create several forms using YII and GII, but I'll be honest, I don't understand it perfectly. If anyone can explain this to me, I'd really appreciate it.
Basically, I create accessed the form creator here:
index.php/gii/form
I then filled in:
Model Class: Product
View Name: createProduct
View Path: application.views (default)
Scenario: createProduct
When I generate the code, I end up with a file called "createProduct.php" located at:
protected\views\createProduct.php
How do I access this view? I figured something like this should work: http://mysite.com/createProduct (but it doesn't)
What do I do if I want to change the link to be: http://mysite.com/admin/products/createProduct
Any help would be greatly appreciated!
Gii tells you to modify your controller. It shows the code you should insert after generating process. When you do this you'll be able to access your form by http://yoursite.com/controller/action
You can manage your urls using UrlManager. Look this article in docs - http://www.yiiframework.com/doc/guide/1.1/en/topics.url

Yii generate errors from parent controller

I just started using Yii, coming from Codeigniter (CI). I'm trying to set up a situation where the application will check a users credentials before they can even access the site. In CI, I would create a parent controller, put my checks in there, and then inherit that parent controller. I've been trying to do the same thing with Yii, but with no luck.
I first created an init() method (for some reason I can't put the code in a __construct() method). I then perform my check, which works fine. I can throw a new CHttpException, but that looks ugly. How do I use Yii's built in error handling to accomplish what I want to do?
For simple login rules you should just implement the 'accessControl' filters from Yii see Yii documentation on authorizations.
Another way would be to throw the Exception like you already did, and write custom Http error views, place it in the yerfolder/protected/views/system/ (see the yii/framework/views directory for examples)
I solved this by sending the error to the site/error view and then calling Yii::app()->end() to keep the child controllers from loading.