vegabson Posted July 1, 2021 Share Posted July 1, 2021 i've tried whit a lot of solutions from other posts but nothing seems to be working this part is where im having trouble but i dont know how to get it to work ``` $this->load->library('form_validation'); $this->load->library('form'); ``` Controler ``` <?php namespace App\Controllers; class Home extends BaseController { public function __contruct() { parent::__construct();// you have missed this line. } public function index() { helper (['form']); return view('inicio'); } public function descarga() { return view('filesnames'); } public function conta() { $this->load->library('form_validation'); $this->load->library('form'); return view('contact/index'); } public function pregu() { return view('preguntas'); } public function dud(){ return view('duda'); } public function contact() { $autoload['libraries'] = array('session','Email','form','form_validation'); $autoload['helper']=array('form', 'url'); //Set form validation $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[3]|max_length[20]'); $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|min_length[0]|max_length[60]'); $this->form_validation->set_rules('message', 'Message', 'trim|required|min_length[5]|max_length[200]'); //Run form validation if ($this->form_validation->run() === FALSE) { $this->load->view('contacto'); } else { //Get the form data $name = $this->input->post('name'); $from_email = $this->input->post('email'); $subject = $this->input->post('subject'); $message = $this->input->post('message'); //Web master email $to_email = 'admin@domain.com'; //Webmaster email, who receive mails //Mail settings $config['protocol'] = 'smtp'; $config['smtp_host'] = 'ssl://smtp.gmail.com'; $config['smtp_port'] = '465'; $config['smtp_user'] = 'mail@domain.com'; // Your email address $config['smtp_pass'] = 'mailpassword'; // Your email account password $config['mailtype'] = 'html'; // or 'text' $config['charset'] = 'iso-8859-1'; $config['wordwrap'] = TRUE; //No quotes required $config['newline'] = "\r\n"; //Double quotes required $this->email->initialize($config); //Send mail with data $this->email->from($from_email, $name); $this->email->to($to_email); $this->email->subject($subject); $this->email->message($message); if ($this->email->send()) { $this->session->set_flashdata('msg','<div class="alert alert-success">Mail sent!</div>'); redirect('contact'); } else { $this->session->set_flashdata('msg','<div class="alert alert-danger">Problem in sending</div>'); $this->load->view('contacto'); } } } } ``` view ``` <body class="ecommerce"> <div class="header"> <div class="container"> <a class="site-logo" href="<?= site_url('/'); ?>"><img src="assets/images/home/logou2.png" class="logosi" alt=""></a> <a href="javascript:void(0);" class="mobi-toggler"><i class="fa fa-bars"></i></a> </div> <!-- BEGIN NAVIGATION --> <div class="header-navigation"> <ul> <li><a href="<?= site_url('/'); ?>">Inicio</a></li> <li><a href="<?php base_url()?>Asistentev16.apk" download="Asistentev16.apk">Descargar</a></li> <li><a href="<?= site_url('/cont'); ?>">Contactanos</a></li> <li><a href="<?= site_url('/faq'); ?>">Preguntas Frecuentes</a></li> </ul> </div> </div><br> <div class="container"> <h2>Contact</h2> <div class="row"> <?php $validation = \Config\Services::validation(); ?> <div class="col-lg-6"> <?php echo $_SESSION['msg']; ?> <form action="<?php echo base_url('/submit-form') ?>" method="post"> <div class="form-group">Nombre <?php echo form_input(array('name' => 'name', 'id' => 'name', 'size' => '50', 'value' => set_value('name'))) ?> <?php if ($validation->getError('name')): ?> <div class="invalid-feedback"> <?= $validation->getError('name') ?> </div> <?php endif; ?> </div> <div class="form-group">Email <?php echo form_input(array('email' => 'email', 'id' => 'email', 'size' => '50', 'value' => set_value('email'))) ?> <?php if ($validation->getError('email')): ?> <div class="invalid-feedback"> <?= $validation->getError('email') ?> </div> <?php endif; ?> </div> <div class="form-group">Asunto <?php echo form_input(array('subject' => 'subject', 'id' => 'subject', 'size' => '50', 'value' => set_value('subject'))) ?> <?php if ($validation->getError('subject')): ?> <div class="invalid-feedback"> <?= $validation->getError('subject') ?> </div> <?php endif; ?> </div> <div class="form-group">Mensaje <?php echo form_input(array('message' => 'message', 'id' => 'message', 'value' => set_value('message'))) ?> <?php if ($validation->getError('message')): ?> <div class="invalid-feedback"> <?= $validation->getError('message') ?> </div> <?php endif; ?> </div> <button name="submit" type="submit" class="btn btn-primary" />Send</button> </form> </div> </div> </body> ``` Quote Link to comment https://forums.phpfreaks.com/topic/313022-error-call-to-a-member-function-library-on-null/ Share on other sites More sharing options...
Psycho Posted July 1, 2021 Share Posted July 1, 2021 I'm assuming the issue is within the class "BaseController". Is that where the methods load and library are defined? It would seem to me that the call to 'load' is returning null instead of an object, which causes the error when the 'library' method is called. Quote Link to comment https://forums.phpfreaks.com/topic/313022-error-call-to-a-member-function-library-on-null/#findComment-1587724 Share on other sites More sharing options...
vegabson Posted July 1, 2021 Author Share Posted July 1, 2021 (edited) 41 minutes ago, Psycho said: I'm assuming the issue is within the class "BaseController". Is that where the methods load and library are defined? It would seem to me that the call to 'load' is returning null instead of an object, which causes the error when the 'library' method is called. what should i do? im a noob programing php and codeigniter Edited July 1, 2021 by vegabson Quote Link to comment https://forums.phpfreaks.com/topic/313022-error-call-to-a-member-function-library-on-null/#findComment-1587725 Share on other sites More sharing options...
maxxd Posted July 2, 2021 Share Posted July 2, 2021 It looks like you're mixing versions of CodeIgniter - version 3 used load() while version 4 uses namespaces. I'm pretty sure there's an upgrade doc somewhere (it's been a bit since I've worked with CI so I don't remember specifically). Quote Link to comment https://forums.phpfreaks.com/topic/313022-error-call-to-a-member-function-library-on-null/#findComment-1587777 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.