Welcome Guest, Not a member yet? Register   Sign In
Codeigniter + smarty problem with pass variable template to model
#1

(This post was last modified: 07-06-2015, 09:47 AM by StratoKyke.)

I explain my problem.

My model:
PHP Code:
public function info_site($name) {
        
$db $this->load->database('site'TRUE);
        
$db    ->select('name, value')
                        ->
from('arcor_site_setting')
            ->
where('name'$name);
        
$query_thread_view $db->get('');
        return 
$query_thread_view->row_array();
    } 

My controller:

PHP Code:
public function information() {
                
$this->load->model('informations');
                
$information $this->informations->info_site($name);
                
$this->smarty->assign('info'$information);
        } 

view:
Code:
{$info.site_name}

I would like the 'site_name' of view was the variable 'name' of the controller and the model. In this way the result of the variable in the template should be the value of the name.


Small example:

In my view I write
Code:
{$info.site_name}

site_name is passed to the controller and in turn the model

In this way the sql would
PHP Code:
public function info_site(site_name) {
        
$db $this->load->database('site'TRUE);
        
$db    ->select('name, value')
                        ->
from('arcor_site_setting')
            ->
where('name''site_name');
        
$query_thread_view $db->get('');
        return 
$query_thread_view->row_array();
    } 

and as a result it should give me the value of the consideration that will be printed.

There is a solution to this my problem?
Reply
#2

It's a little difficult to figure out what problem you're trying to solve, but the controller code you've included does not pass the string to your model.
Reply
#3

(This post was last modified: 07-06-2015, 09:51 AM by StratoKyke.)

What I need is to write in the template function with the variable to print the value of the consideration.


EDIT: the controller is a MY_Controller In this way the function is always available
Reply
#4

I fix the problem in this way:

MY_Controller.php
PHP Code:
class MY_Controller extends CI_Controller {
        public function 
__construct(){
                
parent::__construct();
                
$this->information();
        }
        public function 
information() {
                
$this->load->helper('info');
        }


Model:
PHP Code:
    public function info_site($name) {
        
$db $this->load->database('site'TRUE);
        
$db    ->select('value')
                        ->
from('arcor_site_setting')
            ->
where('name'$name);
        
$query_info_view $db->get('');
        foreach (
$query_info_view->result() as $row){
            echo 
$row->value;
        }
    }


helper:
PHP Code:
function Info($name) {
    
$CI get_instance();
    
$CI->load->model('informations');
    
$CI->informations->info_site($name);


PHP Code:
{info(name)} 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB