CodeIgniter Forums
Codeigniter + smarty problem with pass variable template to model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Codeigniter + smarty problem with pass variable template to model (/showthread.php?tid=62364)



Codeigniter + smarty problem with pass variable template to model - StratoKyke - 07-06-2015

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?


RE: Codeigniter + smarty problem with pass variable template to model - mwhitney - 07-06-2015

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.


RE: Codeigniter + smarty problem with pass variable template to model - StratoKyke - 07-06-2015

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


RE: Codeigniter + smarty problem with pass variable template to model - StratoKyke - 07-06-2015

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)}