Welcome Guest, Not a member yet? Register   Sign In
Get image url from model good practice?
#13

(This post was last modified: 11-12-2015, 03:03 AM by sintakonte.)

it was never intended to (ab)use Data Objects to load Views
you should pass your prepared data array from a model to a controller
and in your controller load the view - as described by many many users here

if you want to follow my approach it is a bad practice to load views in a data Object like you do in your Proprietati_Object
The purpose of a data object is to clean up your models and let the objects do all the work which are related to the Objects Data

a simple example would be:
if your database contains 2 columns discount and price and you want the calculated price - than your object can do the work

PHP Code:
class Proprietati_Object
{

    public 
$discount 10;
    public 
$price 20;

    public function 
__construct(){

 
           $this->_ci get_instance();
    }
    
    public function 
getPrice()
    {
        return (
$this->price * ((100 $this->discount) / 100));
    }



and i don't quite get your adaption of the autoloader function

PHP Code:
   public function autoloadCoreObjects($class)
 
   {
 
       $path = array(
 
           'objects/',
 
       );

 
       $class explode('_'$class);
 
       foreach($path as $dir) {
 
           if (file_exists(APPPATH.$dir.$class[0]."_Object".'.php'))
 
               require_once(APPPATH.$dir.$class[0]."_Object".'.php');
 
       }
 
   

this does the same as my posted function except the fact that you use for some weird reason explode to split the name in 2 partials.
Reply


Messages In This Thread
RE: Get image url from model good practice? - by sintakonte - 11-12-2015, 02:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB