TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
How to return a view without encoding it with ajax ?
  • Hi, I'm trying to return the view of a pagination module via ajax but I do not manage :(

    kohana 3.3

    my controller :


    class Controller_Depots extends Controller {

    public function before()
    {
    parent::before();

    $this->auth = Auth_Ldap::instance();
    $this->o = new stdClass();

    // On s'assure que la session ne soit pas expirée
    if ( !$this->auth->logged_in() )
    {
    $this->request->action('session_expiree');
    }
    }

    public function after()
    {
    // On retourne le resultat JSON
    $json = json_encode($this->o);
    $this->response->body($json);

    parent::after();
    }

    public function action_session_expiree()
    {
    $this->o->session['lost'] = 0;
    $this->o->session['redirection'] = URL::site();
    Model_Logs::write('', 'Erreur', 'Controller_Depots', 'Session expirée ... ');
    }

    public function action_ajax_lister()
    {

    $u = Session::instance()->get('infos_gestionnaire');

    $utilisateur = ORM::factory('Utilisateurs')
    ->where('uid', '=', $u['uid'])
    ->find();

    $groupes_admin = Kohana::$config->load('grepo.groupes-admin');
    $utilisateurs_admin = Kohana::$config->load('grepo.utilisateurs-admin');

    $sz = "etat IN ('I', 'C', 'A', 'M')";

    if ( in_array($u['gid'], $groupes_admin) || in_array($u['uid'], $utilisateurs_admin) )
    {
    $total_depots = ORM::factory('Depots')->where(DB::expr($sz), '=', true)->count_all();

    $pagination = Pagination::factory(
    array(
    'total_items' => $total_depots,
    'items_per_page' => 10, // this will override the default set in your config
    )
    );

    $current_depots = ORM::factory('Depots')
    ->offset($pagination->offset)
    ->limit($pagination->items_per_page)
    ->where(DB::expr($sz), '=', true)
    ->find_all();

    $depots = $current_depots;

    $this->o->view = $pagination->render();

    }
  • I managed jsut by doing a simple : echo $this->o->view; in my after method but ....
    Now another problem :
    got 2 returns : 1 json encode and a view ...
    My application crashed and can't make distinction between the 2 returns.
  • I wonder if the easiest way should be to build an pagination object in my controller, to return it encoded in Json , then to build HTML view on client side with javascript ... :(

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion