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

Helper
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

function 
infoServer($name) {
    
$CI get_instance();
    
$CI->load->model('informations');
    
$CI->informations->info_server($name);


Model
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class 
Informations extends MY_Model {
    public function 
__construct() {
        
parent::__construct();

    }
    public function 
info_server($name) {
        
$db $this->load->database('site'TRUE);
        
$db    ->select('value')
                        ->
from('arcor_server_setting')
            ->
where('name'$name);
        
$query_info_view $db->get('');
        foreach (
$query_info_view->result() as $row){
           echo 
$row->value;
        }
    }


MY_Controller
PHP Code:
class MY_Controller extends CI_Controller {
        public function 
__construct(){
                
parent::__construct();
                
$this->information_server();
        }
        public function 
information_server() {
                
$this->load->helper('infoserver');
        }
      

In the same way I have an My_Model with the same content.

When I use infoServer('with the name of value') The result is printed on the top page. But not where I would actually. Dentrol and variables or functions inside. Only at the top.

While if I use it in a template it works perfectly.

Any solution?

I want to use the function so that when you call me the exact result, which it does, but it should work this way:

This
$variable = 'hello';
and this
$variable = infoServer('with the name of value');
They should be the same.

While at the time if I use the function produces the result I described before.

Thanks for the support.
Reply


Messages In This Thread
foreach in models and controller - by StratoKyke - 07-07-2015, 06:39 PM
RE: foreach in models and controller - by kenjis - 07-08-2015, 01:41 AM
RE: foreach in models and controller - by kenjis - 07-08-2015, 04:48 AM
RE: foreach in models and controller - by kenjis - 07-08-2015, 05:07 AM
RE: foreach in models and controller - by kenjis - 07-08-2015, 05:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB