Welcome Guest, Not a member yet? Register   Sign In
help in models and views
#1

[eluser]Unknown[/eluser]
hi every body
i'm creating a simple cms with ci and i have a problem in creating blocks here is the block code im using :
Code:
class Blocks extends Model
{
function Blocks()
    {        
        parent::Model();
    }
function get($pos){
      $this->load->database();
      //select from blocks where block_position =position and active = 1 and show in section name
      //do foreach and get type and function show by type
      $sql = "SELECT * FROM blocks WHERE postion= '$pos' AND active =1";
      $query = $this->db->query($sql);
     foreach ($query->result_array() as $row){
     if ($row['type']=='stat'){
     $row['continent']=$row['continent'];
     }else {
     $bcname=$row['name'];
     $CI =& get_instance();
     $CI->load->model($bcname);
      $returndata = $CI->$bcname->show();
     $row['continent']= $returndata;
     }
    
     $result[] = $row;
     $this->load->view($row['view'], $row);//this is the broblem
     }
    
      }

every thing work fine but the blocks is show in the front of my view file and i didn't figure what is going wrong
here is my view file
Code:
<?php
$this->load->view($head);
?>
echo $blocks;//returned from the controller //[[$data['blocks']=$this->Blocks->get('right');]]
<?
$this->load->view($foot);
?>
and i get the blocks in the front of my Main view file not in the position i want them to show in .
please help or just any thought about this issue
#2

[eluser]xwero[/eluser]
This is because the view method outputs to the screen like print_r. In order to have the block where you want it you have to do
Code:
return $this->load->view($row['view'], $row,TRUE);

But i wouldn't recommend you to do this. It's better to use the view method in the controller or the view.
#3

[eluser]Unknown[/eluser]
thanks a lot it worked but in another way
you just give me another idea
thanks again




Theme © iAndrew 2016 - Forum software by © MyBB