ci-blade icon indicating copy to clipboard operation
ci-blade copied to clipboard

Can't call ci inbuilt library inside view

Open shravanjbp opened this issue 8 years ago • 4 comments

When try to access session inside view ite throw error. I have tried fallowing inside view $this->session->flashdata('error') )

Severity: Notice Message: Undefined property: Xiaoler\Blade\Engines\CompilerEngine::$session

Fatal error: Call to a member function flashdata() on null

shravanjbp avatar Jul 15 '17 12:07 shravanjbp

@shravanjbp

if you want to use $this in view,you should

$vars = ['this'=>$this];
$this->blade->view('welcome_message', $vars);

But I don't recommend doing this.

chaclee avatar Jul 19 '17 03:07 chaclee

@rainwsy So there is any better way to achieve this. I can handle session without $this but i need to call some model function inside view.

shravanjbp avatar Jul 19 '17 07:07 shravanjbp

@shravanjbp I do not recommend this, this is not standardized. You should set value in controller

chaclee avatar Jul 20 '17 12:07 chaclee

Try it. Use this in your library $this->factory->share('_ci', get_instance());

Change $this to $_ci Example $_ci->session->flashdata('error')

Iyongbudiarso avatar Aug 27 '17 07:08 Iyongbudiarso