MailSender a predani routeru

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
Mikky
Člen | 6
+
0
-

Ahoj,
tak zas a znova Mailsender. Vytvoril jsem si obecnejsi tridu mailsenderu, dle navodu zde a PHPFashion. Ale ne a ne v sablone mailu udelat link na modul. Vyhodi chybu No route for Panel:System:test() … Mohl by me nekdo nakoupnout prosim kde mam chybu?

config

services:
	mailSender: myApp\MailSender\MailSender

Trida

namespace myApp\MailSender;

use Nette;
use Nette\Diagnostics\Debugger;
use Nette\Application\LinkGenerator;
use Nette\Application\UI\ITemplateFactory;
use Nette\Mail\IMailer;
use Nette\Mail\Message;

class MailSender{

	/** @var LinkGenerator */
	private $linkGenerator;

	/** @var ITemplateFactory */
    private $templateFactory;

	/** @var IMailer */
	private $mailer;

	private $emailFile;


	function __construct(LinkGenerator $generator, ITemplateFactory $templateFactory, IMailer $mailer) {
		$this->linkGenerator = $generator;
		$this->templateFactory = $templateFactory;
		$this->mailer = $mailer;
	}

	function setEmailFile($emailFile) {
		$this->emailFile = $emailFile;
	}

	public function sendEmail() {
		$template = $this->createTemplate();
		$template->setFile(APP_DIR . '/templatesEmail/' . $this->emailFile . '.latte');
		$mail = new Message;
		$mail->setHtmlBody($template);
	}

	protected function createTemplate() {
		$template = $this->templateFactory->createTemplate();
		$template->getLatte()->addProvider('uiControl', $this->linkGenerator);

		return $template;
	}

}

Presenter:

namespace App\PanelModule\Presenters;

use Nette;

class SystemPresenter extends BasePresenter {

	private $mailSender;

	public function __construct(\myApp\MailSender\MailSender $mailsender) {
		$this->mailSender = $mailsender;
	}

	public function startup() {
		parent::startup();
	}

	public function renderTest() {
		$msg = $this->mailSender;
		$msg->setEmailFile('test');

		$mail = $msg->sendEmail();
	}

}

V sablone jiz pouze:

<a n:href="Panel:System:test">Test</a>

Dekuji moc za radu…

David Matějka
Moderator | 6445
+
0
-

a primo z presenteru ti stejny odkaz vytvorit jde? ukaz, jak mas definovane routy

Mikky
Člen | 6
+
0
-

Ano, cela aplikace mi bezi naprosto bez problemu. Routy z presenteru funguji jak maji v pohode. spise mi pripada, jakoby ta service ale o nich nevedela.

namespace App;

use Nette;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;

class RouterFactory {

	use Nette\StaticClass;

	/**
	 * @return Nette\Application\IRouter
	 */
	public static function createRouter() {

		$router = new RouteList;

		$router[] = new Route('//<module>.<domain>.<tld>/index.php', array(
			'module' => 'Panel',
			'presenter' => 'Homepage',
			'action' => 'default',
			'locale' => 'cs'
				), Route::ONE_WAY);

		$router[] = new Route('//<module>.<domain>.<tld>/sitemap.xml', array(
			'module' => 'Panel',
			'presenter' => 'Feeds',
			'action' => 'sitemap',
			'locale' => 'cs'
		));
		$router[] = new Route('//<module>.<domain>.<tld>/robots.txt', array(
			'module' => 'Panel',
			'presenter' => 'Feeds',
			'action' => 'robots',
			'locale' => 'cs'
		));

		$router[] = new Route('https://<module>.<domain>.<tld>/<presenter>/<type>-<title>/<id [0-9]+>/', array(
			'module' => 'Panel',
			'presenter' => [
				Route::FILTER_TABLE => [
					'mapa-kotvist' => 'MapOfMoorings',
				],
			],
			'action' => 'detail',
			'title' => [
				Route::FILTER_IN => function($url) {
					return Nette\Utils\Strings::webalize($url);
				},
				Route::FILTER_OUT => function($url) {
					return Nette\Utils\Strings::webalize($url);
				}
			],
			'type' => [
				Route::FILTER_TABLE => [
					'molo' => 'pier',
					'kotva' => 'anchor',
					'bojka' => 'buoy',
				],
			],
			'locale' => 'cs'
		));

		$router[] = new Route('https://<module>.<domain>.<tld>/<presenter>/<type>/<manufacturer>-<model>/<boatName>-<year>/<id [0-9]+>/', array(
			'module' => 'Panel',
			'presenter' => [
				Route::FILTER_TABLE => [
					'recenze-lodi' => 'BoatsReviews',
				],
			],
			'action' => 'detail',
			'manufacturer' => [
				Route::FILTER_IN => function($url) {
					return Nette\Utils\Strings::webalize($url);
				},
				Route::FILTER_OUT => function($url) {
					return Nette\Utils\Strings::webalize($url);
				}
			],
			'model' => [
				Route::FILTER_IN => function($url) {
					return Nette\Utils\Strings::webalize($url);
				},
				Route::FILTER_OUT => function($url) {
					return Nette\Utils\Strings::webalize($url);
				}
			],
			'boatName' => [
				Route::FILTER_IN => function($url) {
					return Nette\Utils\Strings::webalize($url);
				},
				Route::FILTER_OUT => function($url) {
					return Nette\Utils\Strings::webalize($url);
				}
			],
			'type' => [
				Route::FILTER_TABLE => [
					'plachetnice' => 'sail',
					'katamaran' => 'catamaran',
					'motorak' => 'motor',
				],
			],
			'locale' => 'cs'
		));

		$router[] = new Route('https://<module>.<domain>.<tld>/[<locale cs|en|de>/][<presenter>/][<action>/][<title>/][<id [0-9]+>/]', array(
			'module' => 'Panel',
			'presenter' => [
				Route::VALUE => 'Homepage',
				Route::FILTER_TABLE => [
					'charterove-spolecnosti' => 'CharterCompanies',
					'mapa-kotvist' => 'MapOfMoorings',
					'recenze-lodi' => 'BoatsReviews',
				],
			],
			'action' => [
				Route::VALUE => 'default',
				Route::FILTER_TABLE => [
					'upravit-kotviste' => 'editMooring',
					'pridat-kotviste' => 'createMooring',
					'pridat-lod' => 'createBoat',
					'pridat-recenzi' => 'addReview',
				],
			],
			'title' => [
				Route::FILTER_IN => function($url) {
					return Nette\Utils\Strings::webalize($url);
				},
				Route::FILTER_OUT => function($url) {
					return Nette\Utils\Strings::webalize($url);
				}
			],
			'locale' => 'cs'
		));

		return $router;
	}

}
David Matějka
Moderator | 6445
+
0
-

a kdybys dal do toho renderTest neco jako

echo $this->link(':Panel:System:test');

tak to jde?

jak zkousis to odeslani mailu? normalne z prohlizece?

Mikky
Člen | 6
+
0
-

Ano, to mi normalne vypise spravnou url /system/test/

Zkousim to normalne spoustet pres prohlizec.

Kdyz si vydumpuji $msg v presenteru, tak dostanu:

linkGenerator private => Nette\Application\LinkGenerator #652f
	router private => Nette\Application\Routers\RouteList #d5c3
		cachedRoutes private => array (1) [ ... ]
		module private => ""
		list private => array (6) [ ... ]
	refUrl private => Nette\Http\UrlScript #c573
	presenterFactory private => Nette\Application\PresenterFactory #c50d
		mapping private => array (2) [ ... ]
		cache private => array (1) [ ... ]
		factory private => Nette\Bridges\ApplicationDI\PresenterFactoryCallback #cd13 { ... }
templateFactory private => Nette\Bridges\ApplicationLatte\TemplateFactory #1f7f
	latteFactory private => class@anonymous #cd9a
		container private => Container_dd90c8fe7a #ba9a { ... }
	httpRequest private => Nette\Http\Request #dde5
	user private => Nette\Security\User #f665
	cacheStorage private => Nette\Caching\Storages\FileStorage #e2d0
		dir private => "C:\Server\Apache24\htdocs\www\yachtpanel.cz\app/../temp/cache" (61)
		useDirs private => true
		journal private => Nette\Caching\Storages\SQLiteJournal #55ee { ... }
		locks private => null
	templateClass private => "Nette\Bridges\ApplicationLatte\Template" (39)
mailer private => Nette\Mail\SmtpMailer #fd41
emailFile private => "test" (4)
David Matějka
Moderator | 6445
+
+4
-

jo uz to vidim, problem bude v tech parametrech <domain>.<tld> (a mozna i dalsich), ktere mas predpokladam v BasePresenteru jako persistentni. link generator je ale nezna, takze je bude nutne je tam poslat jako argumenty

Mikky
Člen | 6
+
0
-

Mas pravdu :) Diky moc. Po dlouhe dobe jsem sedl k nette a prehazuji projekt starsi na nove nette. Tak musim kouknout, jestli je toto jeste vubec potreba delat. At to nemusim vzdy davat do promennych.