将参数从视图传递到库,然后在过程代码点火器之后返回 [英] passing parameter from view to library and return after process Code igniter

查看:46
本文介绍了将参数从视图传递到库,然后在过程代码点火器之后返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要构建自定义库.我想将字符串从视图传递到库和进程,然后再返回到同一视图.我的代码如下:

I am going to built the custom library. I want to pass string from view to library and process and then return to same view after. My code looks like:

 <?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;
 ?>

我收到此错误call to member function parser() on a non-object.我该如何解决.

And I get this error call to member function parser() on a non-object. How can I resolve this.

推荐答案

您有一些字符串,该字符串是用逗号粘贴的图像名称的内含数组.使您的工作要求在加载视图的控制器中分离该元素(并因此将其专用于变量).为了更好地说明自己,此代码应保留在加载您在此处发布的视图文件的控制器中.或者换句话说,在同一控制器中生成$prods->images属性.同样,它也不必是库,它可以是同一控制器的(私有/受保护的?)方法.而且,如果您希望在不同的地方使用它,也可以使用helper选项进行回答.

You have got some string that is imploded array of image names glued by comma. Make your job of requested separation of that element (and consequently dedicating it to variable) in controller that loads your view. To explain myself bit better, this code should stay in the controller that is loading view file you posted here. Or in other words, in same controller where is generated $prods->images property. Also it doesn't need to be library, it can be (private/protected maybe?) method of same controller. But also, if you want it on different places used, you answered with helper option too.

这篇关于将参数从视图传递到库,然后在过程代码点火器之后返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆