PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 5, 2022

[FIXED] While passing values from one function to another function the view files are not loading in codeigniter 4?

 March 05, 2022     codeigniter, codeigniter-4, php     No comments   

Issue

I need help. In a Controller when I am calling one function from another function the view files are not loading. Only showing the blank page.

Here in the below code, I need to pass the array $calc from calc() function to sem1() function. The array values are passed in the function but the view files in the sem1() function are not loading, showing only a blank page. I am using CodeIgniter 4. Please help.

    public function calc()
    {
        $calc = [
            'regulation'    => $this->request->getPost("regulation"),
            'branch'        => $this->request->getPost("branch"),
            'calculation'   => $this->request->getPost("calculation"),
            "semester"      => $this->request->getPost("semester")
        ];

        if ($calc['calculation'] == "GPA") {
            if ($calc['semester'] == "Semester 1") {
                $this->sem1($calc);
            }
        }
    }

    public function sem1($calc = '')
    {
        $this->builder->select('elective, sub_code, sub_name');
        $this->builder->where('semester', $calc['semester']);
        $this->builder->where('branch', $calc['branch']);
        $query = $this->builder->get();
        $isElective = [0, 0, 0, 0, 0];

        return view('au/auform', ['query' => $query, 'semester' => $semester, 'isElective' => $isElective]);
    }

Solution

You should add an echo to render view:

public function calc(){
    $calc = [
        'regulation'    => $this->request->getPost("regulation"),
        'branch'        => $this->request->getPost("branch"),
        'calculation'   => $this->request->getPost("calculation"),
        "semester"      => $this->request->getPost("semester")
    ];

    if ($calc['calculation'] == "GPA") {
        if ($calc['semester'] == "Semester 1") {
            echo $this->sem1($calc);
        }
    }
}

For more look up the docs - LINK



Answered By - 丹尺爪工れ
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing