Is Kohana 3 has something like app controller? - kohana-3

im kind a new in kohana 3, i use to work in cakephp they have app_controller to init global setting controller for all controller. so i wonder kohaba has something like this or not
now i just use dispatch to call it in each controller. i try to find it
but what is the right way to do so ?
thank's for any comment =)

Do you mean Kohana_Controller class? Its a parent of all Kohana controllers. Also there is a Kohana_Controller_Template with a default template operations.
But Ko3 usually uses index.php, APPPATH/bootstrap.php and config/ folder for configuration purposes. Take a look here.

thank's biakaveron, now i extend class from template controller
to contain main function example init_controller and others controller will extend from init_controller like "class pages_controller extend init_controller"

I like to create a Controller_App that extends Controller_Template, and every controller extends from it. In it I always have before() and after() methods with, generally, Auth logic in the before() and automagically template rendering in the after() (renders a view based on Request's controller and action). Rarely also I put some app-wide actions in it.

Related

How to implement a SideNavigationViewController into a UIViewController?

A little confused on how to implement this into my main view controller. The example project shows it as a navigation controller, but I wasn't able to add an existing class on a fresh navigation controller or my current UIViewController. I could just be implementing it wrong though. Much appreciation if I can gain some traction on how to work with these.
If you could share some code that would be great.
How things work:
Navigation Controllers
There are currently 4 different Navigation Controllers that each offer their own features. The controllers can be used individually, or together.
SideNavigationViewController
The SideNavigationViewController offers 3 bodies to display content: mainViewController, leftViewController, and rightViewController.
MainViewController
The mainViewController must always exist, and has a facility for transitioning between view controllers using the transitionFromMainViewController method. Using this method is as easy as passing a UIViewController in its first parameter.
sideNavigationViewController?.transitionFromMainViewController(InboxViewController())
There are further parameters that allow for animations, completions, etc... to be set when transitioning between view controllers.
LeftViewController and RightViewController
The leftViewController and rightViewController can be set only once. To make them dynamic, you would need to use another Navigation Controller as its view controller.
NavigationBarViewController
The NavigationBarViewController offers a NavigationBarView along side the ability to manage two UIViewControllers, the mainViewController and the floatingViewController.
MainViewController
The mainViewController is like the SideNavigationViewController's mainViewController, and has a transitionFromMainViewController method that transitions from view controller to view controller in the body portion of the NavigationBarViewController.
FloatingViewController
The floatingViewController is a modalViewController and when set, it pops over MainViewController and NavigationBarView. Setting that value is like so:
navigationBarViewController?.floatingViewController = InboxViewController()
To close and hide the floatingViewController set it to nil, like so.
navigationBarViewController?.floatingViewController = nil
SearchBarViewController
The SearchBarViewController offers a single transitioning mainViewController, as well, has a SearchBarView at the top. Transitioning the mainViewController is like so:
sideNavigationBarViewController?.transitionFromMainViewController(InboxViewController())
MenuViewController
The MenuViewController is another controller that has a mainViewController, which takes the entire screen. Floating above it, is a MenuView that is used to transition between mainViewControllers.
menuViewController?.transitionFromMainViewController(InboxViewController())
Final Notes
These Navigation Controllers can be used in any combination and any amount of times creating a robust and intricate stack of controllers that act like one.
I hope this helps :)

Liferay overriding JSONAction using hook

Liferay has feature to modify Struts Action using hook which is straight-forward. However I am trying to override getJSON method of RateEntryAction.
The use case is I need total positive score and total negative score instead of average score that Liferay's OOTB rating component provides.
I already have necessary methods readily available in Liferay API to get the total positive and negative scores. I created a custom type just like "stars" and "votes" to write my necessary logic in hook. I was then planning to override struts action represented by /portal/rate_enty to override the method and add negative and positive votes in the json that is already being returned.
But RateEntryAction (which is the original class) is extending JSONAction and overriding getJSON method. Is it possible to override just getJSON method using struts action hook?
I can see this action class in struts-config.xml, so it's a Struts Action.
This is the path you could try to override.
<action path="/portal/rate_entry" type="com.liferay.portal.action.RateEntryAction" />
I would try to override this path, and see if can put your logic there.
RateEntryAction extends from JSONAction , and this one from org.apache.struts.action.Action , which is the same class that PortletAction extends.
Hope this help
As per my research we can only hook com.liferay.portal.struts.PortletAction sub classes, Yeah JSONAction also extend org.apache.struts.action.Action class same as PortletAction, but liferay allow only those classes hookable which comes under PortletAction class not except that.
As RateEntryAction is not a Struts Action, you can't overload it with a Struts Action Hook. I'm not aware of any hookable way to override it, thus my best guess is that you'll have to either go for ext or introduce a whole new JSON API function and hook all places in Liferay that refer to the original implementation to now go to your implementation.
I suspect that in this case an ext plugin will be easier to maintain. Someone correct me if I'm wrong.

mvvmcross TabBarController ViewModel Init() not called?

I have implemented a TabBarController much like the Conference tutorial for iOS. Everything is working well now except it appears that the Init methods on Viewmodels for the tabs never get called as it normally would.
Is there something I forgot to do to ensure that Init is called? If I must, I could move this code to the constructor of the ViewModel, but I'd like to avoid this if possible.
EDIT
I guess what I'm really asking here is if I manually instantiate a viewmodel and "create" a view from it via the extension/helper methods, will init get called at some point in the process? If so, at what point can I expect init to get called on the viewmodel?
The Construction-Initialize-ReloadState-Start (C-I-R-S) sequence is called on an MvxViewModel if it is created using the default ViewModel locator - which is what happens when you call ShowViewModel.
If the ViewModels for the sub-tabs are created by calling new on a ViewModel directly - like in the Conference HomeViewModel.cs#L11 - then obviously this same sequence doesn't happen.
Really the difference here is between:
the tab ViewModels which are just INotifyPropertyChanged objects
the page-level MvxViewModels which are also INotifyPropertyChanged objects, but which you further expect to be initialized within navigations.
If you wanted to unify the two concepts then you probably could... but actually I suspect it might be simpler and cleaner to perhaps give the two class types different names, to just put the init code in the constuctor for the tab view models, or perhaps to just call Init on them yourself in the Home constructor.

How to pass data to layout in Zend 2?

I've looked around, and there are a few links about this in Zend 1 at best. The best solution I've found is
// controller:
return array('viewValue' => 'something');
// layout.phtml
$children = $this->viewModel()->getCurrent()->getChildren();
$viewValue = $children[0]->viewValue;
In the layout, but it seems a little kludgy. It's even stranger because when I do get_class_methods on the layout it doesn't show a viewModel() method. Basically, I've looked around the API (and source code) and haven't found much. Zend 1 also seems to have more access; some old solutions involved getting the view, and directly modifying it, but in Zend 2 we return a new array (or view model). Any tips?
As for why, I'm using a jQuery mobile layout. So the heading is separate from content, but the structure should be the same (should belong in the layout).
The view models are hierarchically build. The top level view model is the "layout" and a child view model is injected after a controller is dispatched. This means you can build quite some tree of models for your application.
The top level view model (so the one representing the layout) is also located in the MvcEvent. That object is passed along in the application during bootstrap, but also linked to the controller when the controller is initialized.
The MvcEvent is accessible with $this->getEvent() in the controller, the view model by $event->getViewModel(). So to cut things short, just do this:
controller MyController
{
public function myAction()
{
$this->getEvent()->getViewModel()->foo = 'bar';
}
}
And in your layout.phtml:
<?php echo $this->foo; ?>
This pretty much is, how it is done. The new Zend\View-Components are pretty much all ViewModels nested into each other. Rob Allen has written a great article about it on how to work with variables throughout ViewModels.
Furthermore most often i think this approach isn't the best way. It'd be much better to have a ViewHelper or a Layout-Placeholder to do the job. Once again a great article has been written, this time by my dear Bakura, aka Michael Gallego.
Currently, either of those approaches would be your way to go.

symfony: form in the layout?

I have a form I need to show on every page. I'd like to put it in the layout rather than defining it in multiple controllers and view templates. I'm not sure how to do this without creating a slot for it, but then I have to define the slot in every template, and I'm back at square one.
My other thought would be to create a custom action class that defines the form and then subclass all my other actions from it, but that seems like overkill.
You could just use a component, easier than a slot, and stick that in your template, only needs to be defined in one place:
<?php include_component('someModule', 'someAction') ?>
I use components and partials in my layouts quite a bit, works well.

Resources