Here I have to limit the words which come from the database to 15 only in Codeigniter. But it shows this error:
Error:
Fatal error: Call to undefined function word_limiter() in /opt/lampp/htdocs/ci/post/application/views/my_admin/profile1.php on line 172
Error
When we use a blog in the admin dashboard then we create a table and fetch all the data but in some cases, the text is too long then the table will look awkward. That’s why we use word_limiter and character limiter.
Generally, when we use the blog on our website then we need it, because of having long text. It is necessary to know how to use word_limiter and character_limiter.
To fix this simply we have to add a text helper because Your Error Clearly Shows That You Need to load the helper first. Here is the Code.
function __construct()
{
parent::__construct();
$this->load->helper('text');
}
Helper Functions
Helpers, as the name suggests, help you with tasks. Each helper file is simply a collection of functions in a particular category. There are URL helpers that assist in creating links; there are form helpers that help you create form elements; text helpers perform various text formatting routines; cookie helpers set and read cookies; file helpers help you deal with files, etc.
Unlike most other systems in CodeIgniter, helpers are not written in an object-oriented format. They are simple, procedural functions. Each helper function performs one specific task with no dependence on other functions.
CodeIgniter does not load helper files by default, so the first step in using a helper is to load it. Once loaded, it becomes globally available in your controller and views.
Helpers are typically stored in your system/helpers or application/helpers directory. CodeIgniter will look first in your application/helpers directory. If the directory does not exist or the specified helper is not located there, CI will instead look in your global system’s “helpers” directory.
Loading a Helper
Loading a helper file is quite simple using the following method:
$this->load->helper('name');
Where name is the file name of the helper, without the .php file extension or the “helper” part.
For example, to load the URL Helper file, which is named url_helper.php, you would do this:
$this->load->helper('url');
A helper can be loaded anywhere within your controller methods (or even within your View files, although that’s not a good practice), as long as you load it before you use it. You can load your helpers in your controller constructor so that they become available automatically in any function, or you can load a helper in a specific function that needs it.