problem s tovarnickou uvnit komponenty
- vosy
- Člen | 532
v presenteru pro vytvoreni komponenty mam
function createComponentSeoTab()
{
return new SeoTabControl();
}
SeoTabControl vypada takto:
class SeoTabControl extends Components
{
public function __construct()
{
parent::__construct();
}
public function render()
{
$this->template->setFile(dirname(__DIR__).'/pages/SeoTab.latte');
$this->template->nadpis = 'XXXX';
$this->template->render();
}
function createComponentSeoPageForm()
{
$fData = array('presenter'=>$this);
$form = $this->PagesFormFactory->seoForm($fData);
return $form;
}
}
a latte:
<div>
<h2>SEO</h2>
<div class="mT20 form-horizontal">
{form seoPageForm}
<div>
<div n:if="$form->hasErrors()">
{control seoPageForm errors}
</div>
<div class="control-group">
{label jazyk class=>"control-label"/}
<div class="controls">
{input jazyk}
</div>
</div>
<div class="control-group">
{label title class=>"control-label"/}
<div class="controls">
{input title}
</div>
</div>
<div class="control-group">
{label desc class=>"control-label"/}
<div class="controls">
{input desc}
</div>
</div>
<div class="control-group">
{label keys class=>"control-label"/}
<div class="controls">
{input keys}
</div>
</div>
<div class="control-group error">
{label url class=>"control-label"/}
<div class="controls">
{input url}
<div class="mT10">{$form[url]->options[description]}</div>
</div>
</div>
<div class="control-group">
<div class="controls">
{input ulozit } {input storno }
{input zpet }
</div>
</div>
</div>
{/form}
</div>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
vysledek je chyba
Component with name ‚seoPageForm‘ does not exist.
fci createComponentSeoPageForm() mam v komponente SeoTabControl ale zkousel jsem ji dat i do presenteru. Ale furt chyba :(
- David Matějka
- Moderator | 6445
Nerieši to náhodou Multiplier?
ne
@vosy: a odkud volas to
var seoPageFormInputHtmlId = ..
? v ukazce to nikde nevidim
- Phalanx
- Člen | 310
Moje komponenta pro kontakt form
<?php
use Nette\Application\UI\Control;
use Nette\Application\UI\Form;
class ContactForm extends Control
{
public function render()
{
$template = $this->template;
...
$this->template->render();
}
protected function createComponentContactForm()
{
$form = new Form();
...
return $form;
}
?>
a pak kdekoliv
<?php
{control contactForm}
?>
- vosy
- Člen | 532
matej21: mno sem blbec, mel jsem javascript v sablone presenteru odkazujici na formular ktery je v komponente.
je v komponente moznost vyuzit fce inject??
a da se v komponente zjistit presenter v jakem je dana komponenta??
nebo si musim ten presenter predavat v constructoru?
Editoval vosy (15. 10. 2013 9:46)
- David Matějka
- Moderator | 6445
volat konstruktor predka neni potreba..
inject metody primo volat nejde, nejakyma zpusobama ale jo – ale nebudu rikat
jak, protoze to neni doporucovany :))
vzdycky by ses mel pokusit o konstruktor injection
takze si dej do SeoTabControl do konstruktoru zavislost PageFormFactory a na
SeoTabControl si udelej tovarnu – bud rucne nebo DIC tovarnu (pouze 2.1), tu
tovarnu injectnes do presenteru, kde pomoci ni v createComponent* metode
vytvoris komponentu
trochu vysvetlene tovarny mas tady a tady
edit:
k tomu jazyk se z presenteru dostanes:
$presenter['seoTab']['seoPageForm']['jazyk']->htmlId();
//$presenter muze byt $this nebo tak - zalezi samozrejme na kontextu
lepsi by ale bylo, kdyby na to presenter nemusel sahat a „nejak“ se o to postarala sama komponenta – nebo alespon dat do SeoTabControl nejakou shortcut pro ziskani toho htmlid, aby presenter nemusel znat vnitrnosti komponenty
Editoval matej21 (15. 10. 2013 12:40)
- vosy
- Člen | 532
hmm tak ted :)
namespace AdminModule;
use \Nette\Application\UI\Form;
class SeoTabControl extends Components
{
public $PagesFormFactory;
public function __construct()
{
parent::__construct();
$this->PagesFormFactory = new PagesFormFactory();
}
public function render()
{
$this->template->setFile(dirname(__DIR__).'/pages/SeoTab.latte');
$this->template->render();
}
function createComponentSeoPageForm()
{
$fData = array('presenter'=>$this->getPresenter());
$form = $this->PagesFormFactory->seoForm($fData);
return $form;
}
}
SeoTab.latte
<div>
<h2>SEO</h2>
<div class="mT20 form-horizontal">
{form seoPageForm}
<div>
<div class="control-group">
{label jazyk class=>"control-label"/}
<div class="controls">
{input jazyk}
</div>
</div>
{snippet seoLanguageSnippet}
<div class="control-group">
{label title class=>"control-label"/}
<div class="controls">
{input title}
</div>
</div>
<div class="control-group">
{label desc class=>"control-label"/}
<div class="controls">
{input desc}
</div>
</div>
PagesFormFactory.php
function seoForm($opt = null)
{
$form = new \Vosy\MyForm();
$presenter = $opt['presenter'];
$form->addSelect('jazyk', 'Jazyk:')
->setAttribute('class', 'chsn_noSearch')
->setItems($presenter->LanguagesRepository->listOfLanguages()
->fetchPairs('id', 'nazev'));
$form->addText('title', 'Title:', null, 200)
->setAttribute('placeholder','Název této stránky v záhlaví');
$form->addText('desc', 'Popis stránky:', null, 200)
->setAttribute('placeholder','Stručný popis této stránky');
$form->addText('keys', 'Klíčové slova:', null, 200)
->setAttribute('placeholder','Klíčové slova této stránky')
vysledna chyba
Call to a member function getLabel() on a non-object
<?php $_input = is_object(„title“) ? „title“ : $_form[„title“];
if ($_label = $_input->getLabel()) echo
$_label->addAttributes(array(‚class‘=>„control-label“)) ?>
nejak se to nemuze dostat k TITLU formulare.
nemusi se do invalideControl vlozit nazev komponenty?
$this->invalidateControl('seoLanguageSnippet');
v renderEdit v presenteru:
$this->template->_form = $this['seoTab']['seoPageForm'];
blbne mi to kddyz dam do SeoTab.latte
{snippet seoLanguageSnippet}
...
{/snippet}
kdyz tam toto nemam tak se formular zobrazi
Editoval vosy (15. 10. 2013 21:13)
- vosy
- Člen | 532
tak formular tak nejak bezi, akorat kdyz zmenim jazyk tak se mi pomoci ajaxu nevrati prednastavene hodnoty poli Title, Popis atd
v prezenteru mam
/* HANDLES */
function handleSeoLanguageChange($value)
{
if($value)
{
$id = $this->getParam('id');
$infoSeo = $this->PageSeoRepository->getInfo($id, $value);
$this['seoTab']['seoPageForm']['jazyk']->setDefaultvalue($value);
$this['seoTab']['seoPageForm']['title']->setValue($infoSeo['title']);
$this['seoTab']['seoPageForm']['desc']->setValue($infoSeo['description']);
$this['seoTab']['seoPageForm']['keys']->setValue($infoSeo['keywords']);
$this['seoTab']['seoPageForm']['url']->setValue($infoSeo['url']);
}
$this->invalidateControl('seoLanguageSnippet');
}
je to volane prez url /pages/edit/30?backlink=zfaxv§ion=seo&do=seoLanguageChange&value=14
funkce se provede ale nevrati se hodnoty z ohraniceni snippet
<div>
<h2>SEO</h2>
<div class="mT20 form-horizontal">
{form seoPageForm}
<div>
<div class="control-group">
{label jazyk class=>"control-label"/}
<div class="controls">
{input jazyk}
</div>
</div>
{snippet seoLanguageSnippet}
<div class="control-group">
{label title class=>"control-label"/}
<div class="controls">
{input title}
</div>
</div>
<div class="control-group">
{label desc class=>"control-label"/}
<div class="controls">
{input desc}
</div>
</div>
<div class="control-group">
{label keys class=>"control-label"/}
<div class="controls">
{input keys}
</div>
</div>
<div class="control-group error">
{label url class=>"control-label"/}
<div class="controls">
{input url}
<div class="mT10">{$form[url]->options[description]}</div>
</div>
</div>
{/snippet}
<div class="control-group">
<div class="controls">
{input ulozit } {input storno }
{input zpet }
</div>
</div>
</div>
{/form}
</div>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
a tato sablona je nacitana Componentou:
namespace AdminModule;
use \Nette\Application\UI\Form;
class SeoTabControl extends Components
{
public $PagesFormFactory;
public function __construct()
{
parent::__construct();
$this->PagesFormFactory = new PagesFormFactory();
}
public function render()
{
$this->template->setFile(dirname(__DIR__).'/pages/SeoTab.latte');
$this->template->_form = $this['seoPageForm'];
$this->template->render();
}
function createComponentSeoPageForm()
{
$fData = array('presenter'=>$this->getPresenter());
$form = $this->PagesFormFactory->seoForm($fData);
return $form;
}
}