开发者

The problem with creating a library for codeigniter?

I create ​​a library and function show, outputs (results) the Library sent for control, but there's in view page following error. What is in your opinion problem?

i put outputs to Controller as return $info; return $results; return $offset; and they of Controller echo in view as: $data['num_count'] = $info; $data['results'] = $results; $data['offset'] = $offset;

error:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: info

Filename: admin/a开发者_如何转开发ccommodation.php

Line Number: 29

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: results

Filename: admin/accommodation.php

Line Number: 30

Fatal error: Call to a member function result() on a non-object in D:\xampp\htdocs\Siran-mehdi\system\core\Loader.php(679) : eval()'d code on line 46


When you call return, it quits the function at that point, and it doesn't return literally $info so you can keep using that name, but the data inside of that variable.

At the end of your library, change the three returns to something like:

return array('num_count' => $info, 'results' => $results, 'offset' => $offset);

This will return an associative array.

and in your controller:

  $data = $this->siran->show($where, $table, $url_pag);

Where $data will become that array returned by the library.


Return it as array

return array('num_count' => $info, 'results' => $results, 'offset' => $offset);

And actually, in MVC pattern, that much like Model job instead library, since it related with your database abstraction. You create a Library for other task, which ussually is a common task you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜