GithubHelp home page GithubHelp logo

nette / component-model Goto Github PK

View Code? Open in Web Editor NEW
257.0 36.0 9.0 225 KB

⚛ Component model foundation for Nette.

Home Page: https://doc.nette.org/component-model

License: Other

PHP 100.00%
nette nette-framework php component-object-model component-tree

component-model's Issues

Container::getComponent() throws exception for already attached components

Because there is a check for component parent presence in https://github.com/nette/component-model/blob/master/src/ComponentModel/Container.php#L142 it's impossible return already created and attached controls.

class MyControl {

protected function createComponentTest() {
  return $this->anotherControlParent->getComponent("Test");
}

If another parent has attached component "test", exception about unknown component "test" is thrown. Throw such exception in this situation is misleading.

Maybe such component don't need to be attached to current parent but getComponent() method can return such component. That component is already attached to another parent doesn't matter.

Can Container implement IteratorAgregate?

Describe use case:
If i prepare structure of the form by $form->addContainer('foo'); in every template i must use {foreach $form->getComponent('foo')->getComponents() as $key => $input} this help make shorter {foreach $form->getComponent('foo') as $key => $input}, because i never need parameters from getComponents() $deep and $fileter in template.

Implementation is easy.

namespace Nette\ComponentModel;

use Nette;

class Container extends Component implements IContainer, \IteratorAggregate
{

	public function getIterator()
	{
		return $this->getComponents();
	}

}

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.