joomla3.0 - Joomla 3.0 One component with multiple views -
i'm new joomla , i'm trying build single component shows categories of items, , when category clicked, leads second view listing relevant items. now, can first view working. not sure base file, controller, , view files second view working. tried looking answer several days couldn't find relevant.
i want keep in single controller , choose correct view based on requested task. now, have request as
index.php?option=com_products&task=listing&cat=
there's going 3 total tasks, 3 total views. therefore didn't want bother multiple controllers.
- is possible have 1 controller choose between 3 different views? if yes, how?
- would having multiple views necessitate multiple controllers, keep mvc style? if yes, how do that?
structure:
com_categories ---categories.php ---controller.php ---models\categories.php ---models\listing.php ---views\categories\view.html.php ---views\categories\tmpl\default.php ---views\listing\view.html.php ---views\listing\tmpl\default.php
categories.php
$controller = jcontrollerlegacy::getinstance('categories'); $controller->execute(jrequest::getcmd('task')); $controller->redirect();
controller.php
class categoriescontroller extends jcontrollerlegacy { /* * main controller: shows categories * chosen default. */ function display() { $view = $this->getview( 'categories', 'html' ); $view->setmodel($this->getmodel('categories'), true ); $view->setlayout( 'default' ); $view->display(); } /* * listing controller: shows list of items after category clicked */ function listing() { // passes category id model $cat = jrequest::getvar( 'cat', '1' ); $model = $this->getmodel('listing'); $model->setstate('cat', $cat); $view = $this->getview( 'listing', 'html' ); $view->setmodel($model, true ); $view->setlayout( 'default' ); $view->display(); } }
listing\view.html.php
class categoriesviewlisting extends jviewlegacy { function display($tpl = null) { $doc =& jfactory::getdocument(); // assign data view $this->item = $this->get('products'); $this->title = $this->get('category'); // display view parent::display($tpl); } }
if needs views there no need use sub controllers. instead of using task=taskname use view=viewname , add view folder inside /components/com_name/views (copy 1 of existing).
or skip , build using component creator.
Comments
Post a Comment