Registracni formular nelze zobrazit
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- michalll
- Člen | 7
Ahoj zacinam s nette a vytvoril jsem si prihlasovaci formular ten mi spravne funguje a chci stejnym zpusobem vytvorit jeste registracni a volat ho stejne jako ten prihlasovaci ale nemuze mi ho najit pise mi to :
Nette\InvalidStateException
Resource ‚Admin:Registr‘ does not exist
muj RegistrPresenter
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace App\AdminModule\Presenters;
`
use Nette\Application\UI\Form;
use Nette\Security\AuthenticationException;
/**
* Description of RegistrPresenter
*
* @author michal
*/
class RegistrPresenter extends BasePresenter {
private $users;
protected function startup() {
parent::startup();
$this->users= $this->context->user;
}
public function renderRegistr(){
}
protected function createComponentRegistrForm(){
$form = new Form;
$form->addText('name', 'Jméno');
$form->addText('email', 'E-mail: *', 35)
->setEmptyValue('@')
->addRule(Form::FILLED, 'Vyplňte Váš email')
->addCondition(Form::FILLED)
->addRule(Form::EMAIL, 'Neplatná emailová adresa');
$form->addPassword('password', 'Heslo: *', 20)
->setOption('description', 'Alespoň 6 znaků')
->addRule(Form::FILLED, 'Vyplňte Vaše heslo')
->addRule(Form::MIN_LENGTH, 'Heslo musí mít alespoň %d znaků.', 6);
$form->addPassword('password2', 'Heslo znovu: *', 20)
->addConditionOn($form['password'], Form::VALID)
->addRule(Form::FILLED, 'Heslo znovu')
->addRule(Form::EQUAL, 'Hesla se neshodují.', $form['password']);
$form->addSubmit('send', 'Přihlásit');
$form->onSuccess[] = $this->processRegistrForm;
return $form;
}
public function processRegistrForm(Form $form) {
try {
$values = $form->getValues();
$new_user_id = $this->users->register($values);
if($new_user_id){
$this->flashMessage('Registrace se zdařila, jo!');
$this->redirect('Sign:in');
}
} catch (AuthenticationException $e) {
$form->addError($e->getMessage());
$this->flashMessage('Registrace se nedařila, jo!');
}
}
}
a zde @layout.latte
<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="utf-8">
<title>{block title|striptags}Naše první aplikace{/block}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
{* Styles *}
<link href="{$basePath}/css/bootstrap.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
{block head}{/block}
</head>
<body>
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" n:href="Homepage:">Databáze knih</a>
</div>
<div class="navbar-collapse collapse">
{if !$user->isLoggedIn()}
{form loginForm, class=>'navbar-form navbar-right'}
<div class="form-group">{input email, class=>'form-control',placeholder=>'Email'}</div>
<div class="form-group">{input password, class=>'form-control',placeholder=>'Heslo'}</div>
{input send, class=>'btn btn-success'}
{/form}
{else}
<ul class="nav navbar-nav navbar-right">
{if $user->isInRole('admin')}
<li><a n:href=":Admin:auth:login">Administracie</a></li>
<li><a n:href=" :Admin:registr:registr">Registrovat</a></li>
{/if}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{$user->identity->email}<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a n:href="logout!">Odhlásit</a></li>
</ul>
</li>
</ul>
{/if}
</div>
</div>
</div>
<div class="container theme-showcase" role="main">
<div n:foreach="$flashes as $flash" class="alert alert-{$flash->type}">
<a class="close" data-dismiss="alert">×</a>
{$flash->message}
</div>
{include #content}
</div>
<footer>
</footer>
<script src="{$basePath}/js/jquery-2.1.0.min.js"></script>
<script src="{$basePath}/js/bootstrap.min.js"></script>
<script src="{$basePath}/js/netteForms.js"></script>
<script src="{$basePath}/js/main.js"></script>
{block scripts}{/block}
</body>
</html>
pomohl by mi nekdo prosim co delam spatne? dekuji
Editoval michalll (11. 11. 2014 14:28)
- David Matějka
- Moderator | 6445
nejdriv si precti jak formatovat kod a oprav si to, pred tim to ani nebudu cist…