Welcome Guest, Not a member yet? Register   Sign In
HMVC et Flashdata, Librairie Layout
#1

[eluser]Unknown[/eluser]
Hi everyone,
This is a moment that I use codeigniter, however I have a problem I can not solve

In the first time,

I use HMVC (https://bitbucket.org/wiredesignz/codeig...sions-hmvc) and from the configuration of this one, it is impossible to use flashdata

In my controller I set out my flashdata like this

Code:
$this->session->set_flashdata('error', 'Mon message');

In my view

Code:
<?php echo $this->session->flashdata('error'); ?>

Well on my controller after the set_flashdata redirects to another method which it displays my view supposed to display my flashdata

I have the session library is autoload so no worries on that side of the

Do you have an idea of ​​the problem?

In the second time,

I use to manage my layout library

Code:
<?php    if (!defined('BASEPATH')) exit('No direct script access allowed');

class Layout
{
    private $CI;
    private $var    =   array();
    private $theme = 'default';

    /**
     * Constructor
     */
    public function __construct()
    {
            $this->CI =& get_instance();
  
            $this->var['output'] = '';
  
            //  Le titre est compos� du nom de la m�thode et du nom du contr�leur
            //  La fonction ucfirst permet d'ajouter une majuscule
            $this->var['titre'] = ucfirst($this->CI->router->fetch_method()) . ' - ' . ucfirst($this->CI->router->fetch_class());
  
            //  Nous initialisons la variable $charset avec la m�me valeur que
            //  la cl� de configuration initialis�e dans le fichier config.php
            $this->var['charset'] = $this->CI->config->item('charset');
            
            $this->var['css'] = array();
            $this->var['js'] = array();
    }

    /**
     * @param $name
     * @param array $data
     */
    public function view($name, $data = array())
    {
        $this->var['output'] .= $this->CI->load->view($name, $data, true);
        
        $this->CI->load->view('../themes/' . $this->theme, $this->var);
    }

    /**
     * @param $name
     * @param array $data
     * @return $this
     */
    public  function views($name, $data = array())
    {
        $this->var['output'] .=  $this->CI->load->view($name, $data, true);
        return  $this;
    }

    /**
     * @param $titre
     * @return bool
     */
    public function set_titre($titre)
    {
        if(is_string($titre) AND !empty($titre))
        {
            $this->var['titre'] = $titre;
            return true;
            return false;
        }
    }

    /**
     * @param $charset
     * @return bool
     */
    public function set_charset($charset)
    {
        if(is_string($charset) AND !empty($charset))
        {
            $this->var['charset'] = $charset;
            return true;
        }
        return false;
    }

    /**
     * @param $nom
     * @return bool
     */
    public function add_css($nom)
    {
        if(is_string($nom) AND !empty($nom) AND file_exists('./assets/'.$this->theme.'/css/' . $nom . '.css'))
        {
            $this->var['css'][] = css_url($nom, $this->theme);
            
            return true;
        }
        return false;
    }

    /**
     * @param $nom
     * @return bool
     */
    public function add_js($nom)
    {
        if(is_string($nom) AND !empty($nom) AND file_exists('./assets/'.$this->theme.'/js/' . $nom . '.js'))
        {
            $this->var['js'][] = js_url($nom, $this->theme);
            return true;
        }
        return false;
    }

    /**
     * @param $theme
     * @return bool
     */
    public function set_theme($theme)
    {
        if(is_string($theme) AND !empty($theme) AND file_exists('./application/themes/' . $theme . '.php'))
        {
            $this->theme = $theme;
            return true;
        }
        return false;
    }
}
    
/* End of file layout.php */
/* Location: ./application/libraries/layout.php */

In a librairy that I am creating, I have a send_email method (no need to describe the function lol)

Code:
private function send_email($email, $data)
    {
        $this->CI->load->library('email');
        $this->CI->layout->set_theme('email');    

        $this->CI->email->from($this->CI->config->item('acl_email_admin'), $this->CI->config->item('acl_email_from'));
        $this->CI->email->to($email);  
        
        $this->CI->email->subject($this->CI->lang->line('acl_email_activation_subject'));

        $this->CI->email->message($this->CI->layout->view('auth/email_activation', $data, true));    
        
        $this->CI->email->send();
    }

Except that it is impossible for me to use a layout in sending email.
The library is autoload, it works perfectly in a controller and if I use

Code:
$this->CI->email->message($this->CI->load->view('auth/email_activation', $data, true));

It works perfectly.

An idea of the potential problem?

Thank you in advance

Ps: sorry for my english is bad, I'm French

Regards
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

With regards to your flashdata problem:

Are you using database sessions? If so, do you have a hook that only saves session data at the end of controller execution?

Enabling the [url="http://ellislab.com/codeigniter/user-guide/general/profiling.html"]profiler[/url] may help you see what's going on.

With regards to your template problem, it looks like $this->CI->layout->view() is not returning any data. Something like this might work:
Code:
// Start buffering the output.
ob_start();

// Output the view.
$this->CI->layout->view('auth/email_activation', $data);

// Get the buffer contents and use it for the email body, and clean the current buffer.
$this->CI->email->message(ob_get_clean());

Hope this helps.




Theme © iAndrew 2016 - Forum software by © MyBB