I am going to create a custom library. I want to pass a string from the view to the library and the process, and then return to the same view after. My code looks like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); //return profile pic of img arrays. class MultiImageParser { function parser($multiImage) { //get $prods->images here as parameter $images = $multiImage; //gets multiple image from controller like 1.jpg,2.jpg,3.jpg $pieces = explode(",", $images); //explode make arrays. $one = $pieces[0]; return $one; } }
<?php $CI =& get_instance(); $CI->load->library('multiImageParser'); //loading library from view $profilepic = $CI->multiImageParser->parser($prods->images); echo $profilepic; ?>
And I get this error call to member function parser() on a non-object. How can i solve this.
call to member function parser() on a non-object
The problem is the way the library method is called. According to CI Documentation - Creating Libraries :
Object instances will always be lowercase
$this->someclass->some_function(); // Object instances will always be lower case
So, in your case, it should be:
$profilepic = $this->multiimageparser->parser();
, , MVC
:
public function controller_method() { $this->load->library('MultiImageParser'); $img = $this->multiimageparser->parser(); $data = array( "profilepic" => $img ); $this->load->view('view_name', $data); }
echo $profilepic;
, , . (, , ) , . , , , . , , , $prods->images. , , (/, ?) . , , .
$prods->images
Source: https://habr.com/ru/post/1672326/More articles:Android data binding tests not run in NoClassDefFoundError module - javapassing the value of a variable from the library to the controller, and then for viewing in CI 3.0 - jsonJava compiler version for Spring Boot Maven build - spring-bootcodeigniter данные передача контроллер-> библиотека-> просмотр - phpTransfer data from the library to the controller, and then for viewing in CodeIgniter 2 - model-view-controllerSpring Finalize boot drive endpoint - javathis._ngZone.onMicrotaskEmpty.first () - code explanation - angularPython / Pandas - combining the average and minimum number of groups - pythonUnit test extension in Visual Studio 2017 - c #Does Jest reset a JSDOM document after each set or test? - testingAll Articles