Welcome Guest, Not a member yet? Register   Sign In
Several questions concerning CI4 controller
#2

(03-24-2020, 09:03 AM)bitshifter Wrote: 1.) I want to put the $data array outside the whole class or outside the functions (both possible in C/C++) and pass them as a parameter to the function so there is less code. How can I accomplish that in Codeigniter/php?

There is more than one way to clean up the $data code. One easy way is to create a class property.

PHP Code:
class Contact extends Controller
{
    public $data = [
 
    'title' => 'Contact',
 
    'src' => 'images/logo.jpg',
 
    'alt' => 'site dot net site logo',
 
    'heading' => 'Contact',
 
    'success' => 'Thank you for contacting us - we will respond to you shortly'
    ];

//  rest of class


To use the property instead of this code

PHP Code:
echo view('contact/contact'$data); 

You use the $this object reference which can be thought of as being roughly equivalent to the c++ "this" pointer.

PHP Code:
echo view('contact/contact'$this->data); 
Reply


Messages In This Thread
Several questions concerning CI4 controller - by bitshifter - 03-24-2020, 09:03 AM
RE: Several questions concerning CI4 controller - by dave friend - 03-24-2020, 06:03 PM
RE: Several questions concerning CI4 controller - by bitshifter - 03-25-2020, 08:22 AM
RE: Several questions concerning CI4 controller - by bitshifter - 03-25-2020, 12:00 PM
RE: Several questions concerning CI4 controller - by bitshifter - 03-28-2020, 12:13 PM
RE: Several questions concerning CI4 controller - by bitshifter - 04-01-2020, 01:06 PM
RE: Several questions concerning CI4 controller - by bitshifter - 04-17-2020, 07:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB