Welcome Guest, Not a member yet? Register   Sign In
Should I go about this another way? Currently a Library, Should be Model?
#11

[eluser]Thorpe Obazee[/eluser]
This is some interesting read at the Kohana forums about MVC.

http://forum.kohanaphp.com/comments.php?...=23&page=1
#12

[eluser]TheFuzzy0ne[/eluser]
Interesting read, thanks for sharing. I've added it to my [url="http://ellislab.com/forums/viewthread/107773/"]CodeIgniter Resources[/url] post.
#13

[eluser]Thorpe Obazee[/eluser]
First time, I've seen the post. Maybe you should add this to the resource. I've pasted this link at least twice in the forums whenever someone asks for a pagination tutorial.

http://godbit.com/article/pagination-with-code-igniter
#14

[eluser]xwero[/eluser]
Why not use the MVC segmentation in libraries too, the code seems perfect for it.
Code:
Class User_count
{

  function display($view_path,$framework='CI')
  {
       $all_users = 0;
       $active_users = 0;
       $canceled_users = 0;
  
       list($all_users,$active_users,$canceled_users) = $this->{'data_'.strtolower($framework)}();

       ob_start();
       include($viewpath);
       return ob_get_clean();
  }

  function data_ci()
  {
    $CI =& get_instance();
    $CI->load->model('user_count','',TRUE);
        
    return array($CI->user_count->get_all(),$CI->user_count->get_active(),$CI->user_count->get_canceled());
  }

}
// view
<a href="&lt;?php echo site_url('admin/users/active') ?&gt;" class="menuItem">Active (&lt;?php echo number_format($active_users) ?&gt;</a>
<a href="&lt;?php echo site_url('admin/users/canceled') ?&gt;" class="menuItem">Canceled (&lt;?php echo number_format($canceled_users) ?&gt;</a>
<div class=\"menuItemSep\"></div>
<a href="&lt;?php echo site_url('admin/add_user') ?&gt;" class="menuItem">Create new</a>
In CI you can't get the path of a file so you need this function
Code:
function view_path($view)
{
  $CI =& get_instance(); // You can add file_exists check after this line
  return $CI->load->_ci_view_path.$view.EXT;
}
But the main thing is if you ever decide to switch to another framework you can still use the code you made for CI because the display function has no hardcoded framework specific code. And as a bonus the code looks good to.




Theme © iAndrew 2016 - Forum software by © MyBB