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

  • Home
  • SEARCH
  • 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 1054659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:26:26+00:00 2026-05-16T17:26:26+00:00

everybody! I have a new question about Kohana 3, or rather about a module

  • 0

everybody! I have a new question about Kohana 3, or rather about a module structure. I develop a small module called Textblock. It’s about an ordinary page or a small insertion to the site layout (e.g. a greeting or a slogan, company name). It contains both controllers and models. Models inherit Sprig_MPTT. And one feature I’d like to implement is one could be able to call this module like this:

$textblock = Textblock::get_single(1);      //by id
$children  = Textblock::get_children_of(4); //id of parent

and not

$textblock = Sprig::factory('Textblock')->get_single(1);
$children  = Sprig::factory('Textblock')->get_children_of(4);

Those methods are defined in Model_Textblock class as static.

So, I made a wrapper class Textblock, that inherits Model_Textblock. What if I suddenly want change Sprig to Jelly, for example? Foreground won’t change at all. Another advantage, imho, is more clarity for anyone, who wants to use this module (e.g. it could be another programmer in the team).

But there’s a doubt if I’m on a wrong way… So, the question itself: is the suggested a right way to organize my module? Or it’s preferable to keep ordinary Sprig::factory('Textblock') where Textblock’s functionality is needed, remove additional wrapper class and remove static?

  • 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-16T17:26:27+00:00Added an answer on May 16, 2026 at 5:26 pm

    There is no need to extend Model_Textblock. You can create a model instance and call its method:

    class Textblock {
       public static function get_single($id)
       {
          return Sprig::factory('textblock')->get_single($id);
       }
       // etc
    }
    

    But this way you should copy model methods in your static class (not DRY). Also, what if you have more than one model? All you want (as I understand) is to easily change AR driver. So I’d preffer this kind of class:

    class Textblock {   
    
       // saved objects, dont create on model twice
       protected static $_instances = array();
    
       public static function model($name)
       {
          if (! isset(self::$_instances[$name]))
          {
              $model = Sprig_MPTT::factory($name);
              // you can add try..catch to prevent exceptions
              // or add another checks
              self::$_instances[$name] = $model;
          }
          return clone self::$_instances[$name];
       }
    }
    

    and use it like Textblock::model('textblock')->get_single($id).

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

Sidebar

Related Questions

imagine you have simple page like this: Hi everybody. when you click here new
everybody; I have this problem in asp.net, I have a page where I insert
iam new to Entity framework i have learned about using SP and how to
Good morning everybody. I have a question connected with controls and event handling. Lets
Happy New Year everybody,now I am trying to develop my own bot( web crawler
It seems that everybody knows you're supposed to have a clear distinction between the
I just started creating my data-access layer using LinqToSql. Everybody is talking about the
I have some questions about android ui api. Give a example, that I want
Hello everybody I've recently asked this question and I've given up with the 'replace
Hello everybody i hope everybody is doin well, Actually i have a table in

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.