An interview question on the performExecute() in a controller command or taskcommand - wcs

In a recent interview which i attended i was asked a question. It is as follows:
In a controller command we have a method named performExecute().But whenever we want to execute the controller command from any other controller command we will just call
controllerCmdObj.execute();
Why it is so?
Can anybody please answer this question?

Hey its the inheritence, you implement controllercommand interface or extend controllercommandImpl.
Inside the execute method of implemented super class they call performExecute.
So when you call your controller command's execute method the call goes to the execute of super class and from withing that the base class's performExecute gets called.

Related

Attach method for events

I have a question about attach functions on controls.
For example, sap.m.Input has several attach* methods, one of them is attachLiveChange. The question is, does it exist a common attach method?
What am I trying to archive is, for example:
oInput.attach("LiveChange", (oEvent) => doSomething);
sap.ui.base.EventProvider has a method called attachEvent and attachEventOnce, most controls derive from the EventProvider class so you can use said methods to achieve your goal.
https://openui5.hana.ondemand.com/#/api/sap.ui.base.EventProvider/methods/attachEvent
https://openui5.hana.ondemand.com/#/api/sap.ui.base.EventProvider/methods/attachEventOnce

Lithium: How do I access an action through the command line?

I'm trying to run an action via CLI. The action is UsersController::test()
So, I run this:
php libraries/lithium/console/lithium.php \\app\\controllers\\UsersController test
But I keep running into this error:
PHP Fatal error: Call to undefined method lithium\console\Request::get() in /var/www/example.com/libraries/lithium/action/Controller.php on line 154
What am I doing wrong?
See http://li3.me/docs/lithium/console for reference.
As far as I know, it's not possible to call controllers directly from the command line. Although from your error, it seems it's trying to do something.
Instead, create a class that extends from \lithium\console\Command and place that in namespace app\extensions\command. For example, name that class Users. Inside that class, create a method called test() that will be run when you invoke your command via cli.
Now when you run li3 (or lithium.php), it should print all of the available commands and you should see yours in the list. You would call li3 users test and that should run it if you've added lithium/console/li3 to your bin path. Or you could call php -f path/to/lithium.php -- users test which should do the same thing. If you left out test, it will look for a method called run() in your app\extensions\console\Users class and call that.
You could potentially create an instance of your controller and call the test() method, but as you saw, the Request class that is available when running from a web browser is not the same Request class when running from the command-line. It would probably be better to take the business logic in your controller method and move it to another class and then pass in the request parameters from your controller to that method. Then from the console command class, you would similarly call the same centralized method.

Having difficulties extending Zend_Form

Currently I have big difficulties extending Zend_Form.
I have the basic class called Forms_LpaManageEmailForm.
It is used separately and works fine.
Next I've created a new class form
called Default_Form_CartReport witch extends Forms_LpaManageEmailForm.
So the task is to render Default_Form_CartReport and slitely modificate it.
In other words I need all functionality of
Forms_LpaManageEmailForm class but with overriden _addMultiOptionsForMultiSelect() function
(what is done) and changed button label (doesn't solved).
In basic class I have hidden element named id which value is filled with
$this->_entry_id['entry_id']. When I use basic form separately - its woks fine. But
when I run extended form(Forms_LpaManageEmailForm) I see that hidden id element's value is empty. In basic class in construct section I run
Zend debugger(with this line Zend_Debug::dump($this->_entry_id['entry_id'])) to see if the
value is passed. And it's passed :) When I repeat this in init() section it shows NULL...
As I barely understand - the problem lays in init() functions, in the way it is called.
I think something is wrong with Default_Form_CartReport class skeleton.
I've uploaded code to: PASTEBIN
Really need help in this question.
Thank you!
I believe your issues are causing my the fact that Forms_LpaManageEmailForm:: __construct is calling $this->init() directly. if you open the Zend_Form, you will notice that the __construct is also calling the $this->init() function. This cause your init() function to executed twice.
Try to load all your logic & elements solely in the __construct function, and don't use the init() function. also, the __construct function in each form class should always call the parent::__construct before any additional logic.

DelegateCommand<object> test with EventArg parameter mstest

I currently have an event trigger firing a custom trigger action.
The action passes back a EventArgs type of object to the view's view-model.
This is all well and good when I run the code it works perfectly. However, when I come to test this portion of code it all goes a bit rubbish.
As stated We are using an MVVM type pattern so I'm testing the 'Doing' end of the event trigger in my view-model and what I want to do is create a 'mocked' EventArgs object to pass into the execute method of my command under test. However it requires a RoutedEvent as it's ID property as stated above and I don't have access to it's constructor!
Cannot Access Internal Constructor for 'RoutedEvent' here.
Has anyone got any ideas? The code converage in test is more important than the current implimentation so if this is thought to be 'untestable', then I can make changes.
I have answered my own Question I think.
Casting the object passed back from the view at an earlier point means that the object I am passing to the methods under test is more easily created.
This is what I have now for the method under test.
public void DoItemsChanged(IList param)
Before I had
public void DoItemsChanged(object param)
Where the param is a SelectedItemCollection (previously a RoutedEventArgs, but now I use the IvokeCommandAction on the event trigger in the view, passign the SelectedItems). The param is now more easily passed into the method for the test and the code it much more descriptive as well. So it's all good for everyone.

CodeIgniter helper inside controllers

can i call helper functions inside controller classes?
let's say i have this controller with the _open_form method
class User extends Controller {
function _open_form($action){
print_r(form_open($action));
}
}
i tried echoing out the result of form_open()
but it returns null. it seems that helper functions can't be called inside controllers
if your wondering why i need to use it inside the controller instead in the view
because we are required to use the given template parser xD
lolololol
i figured it out. it seems that the view file did not escaped the result of form_open()
try using htmlentities(form_open($action));
it should escape < and > symbols
lol sorry for the stupid question :))
Did you load the helper file?
$this->load->helper('form');
Yes you just need to load it inside your function:
$this->load->helper('form');
More details here http://codeigniter.com/user_guide/general/helpers.html