Nepřdání parametru do komponenty
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.

- boky
 - Člen | 18
 
Cau,
muzete me prosim nakopnout… v novym malym projektu mi nefunguje predavani parametru do komponent
bootstrap:
/**
 * My Application bootstrap file.
 */
use Nette\Application\Routers\Route, \Nette\Application\Routers\RouteList;
// Load Nette Framework
require LIBS_DIR . '/Nette/loader.php';
// Configure application
$configurator = new Nette\Config\Configurator;
$configurator->setProductionMode(array('10.40.10.50', '10.40.10.10'));
$configurator->enableDebugger(__DIR__ . '/../log');
// Enable RobotLoader - this will load all classes automatically
$configurator->setTempDirectory(__DIR__ . '/../temp');
$configurator->createRobotLoader()
	->addDirectory(APP_DIR)
	->addDirectory(LIBS_DIR)
	->register();
// Create Dependency Injection container from config.neon file
$configurator->addConfig(__DIR__ . '/config/config.neon');
$configurator->onCompile[] = function($cfg, $compiler) {
	$compiler->addExtension("components", new DummyExtension());
	$compiler->addExtension("fcomponents", new DummyExtension());
};
$container = $configurator->createContainer();
// Setup router
	$container->router[] = new Route('index.php', 'Front:Default:default', Route::ONE_WAY);
	$container->router[] = $adminRouter = new RouteList('Admin');
	$adminRouter[] = new Route('admin/<presenter>/<action>[/<id>]', 'Dashboard:default');
	$container->router[] = $frontRouter = new RouteList('Front');
	$frontRouter[] = new Route('<presenter>/<action>[/<id>]', 'Homepage:default');
// Configure and run the application!
$container->application->run();
/--
\--
/--php
   factories:
   articles:
      class: FrontModule\Articles(@modelLoader::getModel('front'))
v presenteru:
   protected function createComponentArticles() {
      return $this->context->fcomponents->createArticles();
   }
komponenta:
namespace FrontModule;
class Articles extends \Nette\Application\UI\Control {
   /** @var \Models\Front */
   public $model;
   public function __contruct(\Models\Front $model) {
      $this->model = $model;
   }
   public function render() {
      $this->template->setFile(__DIR__ . '/articles.latte');
      $this->template->render();
   }
   public function handleTest($id) {
      \Nette\Diagnostics\Debugger::dump($id);
   }
}
a v sablone:
<a n:href="test!, id => 7">Test</a>
Vubec nechapu proc to nejde, v jinych projektech mi to normalne funguje.
Moc prosim o jakekoli nakopnuti

- Tomáš Votruba
 - Moderator | 1114
 
boky napsal(a):
a v sablone:
<a n:href="test!, id => 7">Test</a>
V šabloně komponenty? Případně hoď někam na pastebin/gist (ať to tu není plné zdrojáku a dá se číst) šablonu komponenty a použití v šabloně stránky.