Welcome Guest, Not a member yet? Register   Sign In
call controller from another one
#11

[eluser]wiredesignz[/eluser]
It's not a flame... you seem to keep asking for this, and it is not a CI or MVC related question.

Quote: as i said before i cant create an object from another controller to use it in this function because that controller uses libraries, helpers etc…

This is an PHP OOP problem.
#12

[eluser]EugeneS[/eluser]
[quote author="wiredesignz" date="1196531468"]It's not a flame... you seem to keep asking for this, and it is not a CI or MVC related question.

Quote: as i said before i cant create an object from another controller to use it in this function because that controller uses libraries, helpers etc…

This is an PHP OOP problem.[/quote]

ok, so any ideas how to get class methods in my case ?
or the only way is parsing ? i thought might be any one can propose another way ?
#13

[eluser]wiredesignz[/eluser]
Something similar to the Observer Pattern, where each controller has a method of registering itself somewhere with a list of its methods, libraries, helpers etc.

or

Each controller could have a inbuilt method to describe itself.

include($controller)

subclass $controller (somehow defeat the parent::__construct call)

$controller->describe()
#14

[eluser]EugeneS[/eluser]
[quote author="wiredesignz" date="1196533180"]Something similar to the Observer Pattern, where each controller has a method of registering itself somewhere with a list of its methods, libraries, helpers etc.

or

Each controller could have a inbuilt method to describe itself.

include($controller)

subclass $controller (somehow defeat the parent::__construct call)

$controller->describe()[/quote]

kind of description will force me to remember to add/modify all the time Sad

if i would able to destroy constructor (with the library calls) i would be able to just include and create new object ....

i see the only dynamic way is to parse php files Sad

thanks to all...
#15

[eluser]esra[/eluser]
[quote author="wiredesignz" date="1196529123"]The guy needs to understand basic MVC before he can get to all that.[/quote]

This topic comes up over and over again. In his second sentence, he mentions that he knows enough about MVC to realize the request is not typically supported by MVC (i.e., as implied by the Sun Model 2 implementation of MVC versus the Smalltalk MVC implementation) and in the lessor case by CodeIgniter's MVC implementation. Some PHP-based MVC implementations such as Zend and Symfony do promote polymorphism at the framework level to a greater degree than others because OOP is better supported in PHP5.

I think the reason for the frequent reappearance of this topic is less a problem with understanding MVC than it is understanding how to use polymorphism based on the techniques and tools available for both PHP4 and PHP5. PHP4 is pretty much an antique when compared to the OOP support offered in PHP5 and other programming languages.

Lastly, there are no perfect frameworks and not every framework architecture is best suited for every project. Some customization is usually necessary to adapt a framework to meet all of your needs and wants. As Web 2.0 becomes more popular, I think we are going to see MVC frameworks fall to the wayside in favor of other architectural models unless some serious effort is placed on solving the need to start threads such as this one.
#16

[eluser]esra[/eluser]
[quote author="wiredesignz" date="1196533180"]Something similar to the Observer Pattern, where each controller has a method of registering itself somewhere with a list of its methods, libraries, helpers etc.

or

Each controller could have a inbuilt method to describe itself.

include($controller)

subclass $controller (somehow defeat the parent::__construct call)

$controller->describe()[/quote]

This is possible, but it's probably easier to implement in Kohana because both the front controller and controller are extended from an abstract controller class making it easier to support a loosely coupled collection of MVC modules. Then the observer pattern can be implemented from a parent class which could be extended. In any case, it's probably going to result in a system/ hack or a sophisticated hook solution.

There is also the Mediator pattern which can be implemented with or without an Observer. In the former case, action notifications are passed from Collegue objects to the Mediator as class arguments and in the latter case as events using the Observer pattern. The Mediator can then communicate with other subcontrollers in the same module to perform synchronizations between subcontrollers (e.g., updating a input text box after making a selection from a list). But this results in a fundamental architectural model shift from MVC to PAC (Presentation-Abstraction-Control). It is possible to implement the Mediator pattern at the controller level in CI where each controller is a mediator and subcontrollers are collegues, but cross-controller communication would mandate the use of the Observer pattern. The alternate solution is to hack Codeigniter.php as a concrete Mediator or to to use a hook solution.

Both of the above solutions are easier to implement in PHP5.
#17

[eluser]esra[/eluser]
[quote author="EugeneS" date="1196530939"]CAN YOU SUGGEST HOW CAN I RECEIVE ALL THE METHODS OF THE for example 20 CONTROLLERS at once by means of CI without just parsing php files with reg.exps. ?[/color][/quote]

The controllers and associated methods need to be registered somewhere. Could you handle this need using SQL. For example, use an open source or custom packager to install your modules and register the class names and methods in a database table based on the Adjacency List Model or Nested Sets model. This would allow modules to be removed and added as required. Intermixing this with Registry solution mentioned earlier, you could register the methods using SQL or write the methods to a config file which could be loaded by individual controllers or by the front controller via a hook.
#18

[eluser]Rick Jolly[/eluser]
I'm not sure what EugeneS is trying to achieve, but I think you can use get_class_methods() without instantiating the class if that helps. Otherwise you could use the php 5 ReflectionClass or parse the php file the same way that php does using token_get_all(). For an example of both of those methods see amfphp: amfphp/core/shared/util/MethodTable.php.
#19

[eluser]EugeneS[/eluser]
[quote author="Rick Jolly" date="1196551174"] you can use get_class_methods() without instantiating the class if that helps. [/quote]


ohhhh really .... thanks a lot !! i really miss this.




Theme © iAndrew 2016 - Forum software by © MyBB