简体   繁体   中英

How to access Model data from yii template

I'm using aBound yii template for my app. on the left side there is a div with information. But in the template the info is static. I want to access model data, and trying NOT to break MVC pattern.

1) where is the right place to create a Count function ? for example, how many active clients are in the database, is it in Client Model or in Client Controller ?

2) should it be static ?

1) The better approach is to make this function in Client Model, you might use scopes for this.

2) This is static function, since it does not depend on an model instance.

Create a widget under /extensions directory. This is more portable within your application. http://www.yiiframework.com/doc/guide/1.1/en/extension.create#widget

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM