从Codeigniter Template Partials读取数据时出现问题,以及使用控制器重定向

I have two unrelated Codeigniter problems:

(a) I am trying to redirect a user to the dashboard after logging in successfully. i.e. from controller "auth" to controller "dashboard". For some odd reason, it keeps redirecting to auth/dashboard (404 error since it does not exist).

This is what I did:

//Within the auth controller    
    if ($this->auth->login($username, $password)) //Auth->login returns boolean
    {
    redirect('/dashboard', 'refresh');
    # redirect('/dashboard', 'location');  // I tried this too
    # redirect('/dashboard/index', 'refresh');   // I also tried this!
    }

What am I doing wrong, please? It just keeps redirecting to auth/dashboard

(b) I am using Phil Sturgeon's brilliant Codeigniter Template library (without a Parser) and I am unable to receive data sent into a partials file. This data is ONLY needed by the partials file. I have been over the (unfortunately sparse) library documentation, S/O posts on the topic, and also the CI forums to no avail, there seems to be no clear-cut example showing how a partial receives data that a controller assigns to it.

This is how I have been doing it. Please tell me what I must be doing wrong.

// In the controller page
$this->data['user'] = array('info' => 'username', 'value' => 'Cogicero');
$this->data['prefs'] = array('foo' => 'bar');
$this->template
     ->set_partial('header', 'partials/header', $this->data)
     ->set_layout('blog')
     ->build('foobar_view');

And

        //In the header partials page
        <?php
        /* snip */
        print_r($data);
        print_r($prefs);
        print_r($user);
        echo $user["info"];
        echo $prefs["foo"];
        ?>

All the above produce "array does not exist" or "undefined variable" errors! How am I meant to be receiving data within the partials view file?

Thanks

EDIT: Working on a tight deadline so with no solution in sight, I had to abandon Phil Sturgeon's template library and pick up Jens Segers' instead. http://www.jenssegers.be/blog/25/Codeigniter-template-library It is a little similar to Phil's but for some reason the partials are receiving and rendering my data properly. Also, Sergers' template library is very well documented. All is fine now, so I'll accept my own answer to problem (a). Thanks everyone.

查看全部
doushangxianq07480
doushangxianq07480
2012/09/03 17:00
  • redirect
  • codeigniter
  • templates
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复