Welcome Guest, Not a member yet? Register   Sign In
how to keep the variable passed to the view in codeigniter 4
#6

(02-26-2022, 01:54 AM)startup Wrote:
(02-26-2022, 01:22 AM)iRedds Wrote: You don't need to pass the model to the view.
This is bad practice.

i need code below
PHP Code:
cateMenu =1
$getcateMenu 
=$mhome->function('1'

can you  good method to get id folow cate in view page ? i know 'view_ceil' in codeigniter 4 , but id dont like this function

I don't know the logic of your application.
For example, you can create a service that will prepare data for display.
This is a simple example to show the concept.

PHP Code:
class MyService
{
    public function 
doSomething()
    {
        
$data = ['...'];
        \
Config\Services::renderer()->setData($data);
        
        return 
$this;
    }

    public function 
doSomething2()
    {
        
$data = ['...'];
        \
Config\Services::renderer()->setData($data);
        
        return 
$this;
    }
}

class 
MyController extends Controller
{
    public function 
index()
    {
        
$ms = new MyService();
        
$ms->doSomething()->doSomething2();
        
        return 
view('template');
    }

Reply


Messages In This Thread
RE: how to keep the variable passed to the view in codeigniter 4 - by iRedds - 02-26-2022, 08:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB