20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

We first need to configure the Web server so that a URL without the entry script can still be<br />

handled by the entry script. For Apache HTTP server, this can be <strong>do</strong>ne by turning on the<br />

URL rewriting engine and specifying some rewriting rules. We can create the file /wwwroot/<br />

blog/.htaccess with the following content. Note that the same content can also be put in<br />

the Apache configuration file within the Directory element for /wwwroot/blog.<br />

RewriteEngine on<br />

# if a directory or a file exists, use it directly<br />

RewriteCond %{REQUEST_FILENAME} !-f<br />

RewriteCond %{REQUEST_FILENAME} !-d<br />

# otherwise forward it to index.php<br />

RewriteRule . index.php<br />

We then configure the showScriptName property of the urlManager component to be false.<br />

Now if we call $this->createUrl('post/read',array('id'=>100)), we would obtain the URL/post/<br />

100. More importantly, this URL can be properly recognized by our Web application.<br />

Faking URL Suffix<br />

We may also add some suffix to our URLs. For example, we can have /post/100.html<br />

instead of/post/100. This makes it look more like a URL to a static Web page. To <strong>do</strong> so,<br />

simply configure the urlManager component by setting its urlSuffix property to the suffix<br />

you like.<br />

Autenticação e Autorização<br />

Authentication and authorization are required for a Web page that should be limited to<br />

certain users. Authentication is about verifying whether someone is who they claim to be. It<br />

usually involves a username and a password, but may include any other methods of<br />

demonstrating identity, such as a smart card, fingerprints, etc.Authorization is finding out if<br />

the person, once identified (i.e. authenticated), is permitted to manipulate specific<br />

resources. This is usually determined by finding out if that person is of a particular role that<br />

has access to the resources.<br />

<strong>Yii</strong> has a built-in authentication/authorization (auth) framework which is easy to use and<br />

can be customized for special needs.<br />

The central piece in the <strong>Yii</strong> auth framework is a pre-declared user application component<br />

which is an object implementing the [IWebUser] interface. The user component represents<br />

the persistent identity information for the current user. We can access it at any place using<br />

<strong>Yii</strong>::app()->user.<br />

Using the user component, we can check if a user is logged in or not via<br />

CWebUser::isGuest; we can login and logout a user; we can check if the user can perform

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!