Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3228406
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:41:19+00:00 2026-05-17T16:41:19+00:00

I’m working on a project which allows the advanced user to define their own

  • 0

I’m working on a project which allows the advanced user to define their own way of showing the information and access some basic API. For example, I provide a show_search_box() function so that the user can call this function in the view file when they want to show the standard search box, or they could call the function with parameters to customize the search form.

e.g. this code in the template will show a search form with watermark text “Enter keyword here”.

<div><?php show_search_box('Enter keyword here'); ?></div>

What I’m thinking actually is exactly like what WordPress does in its template tags. (http://codex.wordpress.org/Stepping_Into_Template_Tags)

My idea is to create a class that provide all those API functions and pass an object instance of the class to the view file, so users can call the API functions in view like:

<div><?php $API->show_search_box('Enter keyword here'); ?></div>

I think it will work, (but have not tested it yet), but I prefer providing a set of direct called functions just like WordPress. What’s the best way to do this with kohana 3?

======Update: I have tested the method of pass $API object to view, and it works as expected.

class API {
     public function show_search_box($watermark){....}
}

In the controller, pass the $API to the view/template

public function action_index()
{
     $this->template->API = new API();
}

Then call the function inside view/template as described above.
Unlike those controller methods, $API cannot access the controller’s variables unless they’re explicitly assigned: e.g. $API->setVar(‘VarName’, $a_controller_variable), which is quite tedious i think.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:41:19+00:00Added an answer on May 17, 2026 at 4:41 pm

    Well, unlike Kohana 2.3, views don’t execute in the controller namespace, so you can’t simply do $this->something().

    If you have all your functions in one Model, let’s call it API, then you could do this in the view (or base controller if you want it available everywhere)…

    $this->template->internalView = View::factory('your_view')
                                      ->set('API', Model::factory('API));
    

    (assuming you have a <?php echo $internalView; ?> in a parent view).

    Then you could do in your view…

    <div><?php $API->show_search_box('Enter keyword here'); ?></div>
    

    Which will run your method on your model. Views shouldn’t really know about the existence of models, but your case ma be an exception. Perhaps you could use a helper sort of class instead of a model, if you are worried about breaking the MVC paradigm.

    If you want to do what WordPress does (have a bunch of global functions, which I don’t recommend), then you will need to define them somewhere. Kohana doesn’t really have an easy spot to place them, as it doesn’t really cater for a bunch of global functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.