TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Display Search on Different controllers
  • Hey,

    I want to display a search-field on different controllers/views. The search field has the same logic everytime and sends via ajax. I don't want to copy the code to every action where it's needed. What's the best way to achieve this?

  • In the usual way: add the code to a base controller and extend from that. Or make a separate ajax/search controller.

  • Yes, and seperate the view from other views and place it through your template controller.

  • Soo, thanks for your answers. I decided to use the HMVC functionality. In the views where the searchbox is needed I call:

    <?php echo Request::factory('lexikon/searchform')->execute(); ?>

       public function action_searchform()
        {
            $this->auto_render = false;
            $view = View::factory('lexikon/searchform');
            
            // Random Articles
            $entries = ORM::factory('Lexikon_Entries')->where('id', '>=', DB::expr('(SELECT FLOOR( MAX(id) * RAND()) FROM `lexikon_entries` )'))->order_by('id')->limit(6)->find_all();
            $view->bind('random', $entries);
            
            $this->response->body($view);
        }

    When I open the page i get ErrorException [ Fatal Error ]: Cannot redeclare deregister_globals(). I don't know if I've done something wrong, or if this is a bug in Kohana3.3?

  • Okay, found the solution by myself: In my base controller added some phpbb integration which caused to problem. I created a new controller for all those little hmvc snippets that doesn't extend the base controller.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion