• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does helpers, libraries and ThirdParty work?

#1
Hi.

 I need some help here. I can't understand how to use helpers, libraries and thirdParty. If anymore can create the sample of source code and share with me? So that I can look at it. Also, how to auto load helpers, libraries and thirdparty if that is possible. Cause I had go thru the document. But I can't understand it.
Reply

#2
Hello!
I will answer your question in parts.
Helpers can be used this way:

PHP Code:
helper($filename

Documentation link


When a new helper is created, the file name must be convert_helper.php for example and is loaded in the same way as above, in this case helper ('convert')

A library is used as follows:

PHP Code:
<?php

namespace App\Controllers;

use 
App\Libraries\Template;

class 
Account extends Controller
{
    
    
/**
     * Template
     *
     * @var \App\Libraries\Template
     */
    
protected $template;


    public function __construct()
    {
       $this->template = new Template;
    }



To load automatically, use the Base Controller and extend it in your controller classes


PHP Code:
<?php

namespace App\Controllers;

/**
 * Class BaseController
 *
 * BaseController provides a convenient place for loading components
 * and performing functions that are needed by all your controllers.
 * Extend this class in any new controllers:
 *     class Home extends BaseController
 *
 * For security be sure to declare any new methods as protected or private.
 *
 * @package CodeIgniter
 */

use CodeIgniter\Controller;
use 
App\Libraries\Template;

class 
BaseController extends Controller
{

    
/**
     * An array of helpers to be loaded automatically upon
     * class instantiation. These helpers will be available
     * to all other controllers that extend BaseController.
     *
     * @var array
     */
    
protected $helpers = ['array'];


    
/**
     * Template
     *
     * @var \App\Libraries\Template
     */
    
protected $template;


    
/**
     * Constructor.
     */
    
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
    {
        
// Do Not Edit This Line
        
parent::initController($request$response$logger);

        
//--------------------------------------------------------------------
        // Preload any models, libraries, etc, here.
        //--------------------------------------------------------------------
        // E.g.:
        // $this->session = \Config\Services::session();
        
$this->template = new Template;
    }


and your controller extends BaseController
Reply

#3
(03-07-2020, 04:55 AM)MatheusCastro Wrote:
Hello!
I will answer your question in parts.
Helpers can be used this way:

PHP Code:
helper($filename

Documentation link


When a new helper is created, the file name must be convert_helper.php for example and is loaded in the same way as above, in this case helper ('convert')

A library is used as follows:

PHP Code:
<?php

namespace App\Controllers;

use 
App\Libraries\Template;

class 
Account extends Controller
{
    
    
/**
     * Template
     *
     * @var \App\Libraries\Template
     */
    
protected $template;


    public function __construct()
    {
       $this->template = new Template;
    }



To load automatically, use the Base Controller and extend it in your controller classes


PHP Code:
<?php

namespace App\Controllers;

/**
 * Class BaseController
 *
 * BaseController provides a convenient place for loading components
 * and performing functions that are needed by all your controllers.
 * Extend this class in any new controllers:
 *     class Home extends BaseController
 *
 * For security be sure to declare any new methods as protected or private.
 *
 * @package CodeIgniter
 */

use CodeIgniter\Controller;
use 
App\Libraries\Template;

class 
BaseController extends Controller
{

    
/**
     * An array of helpers to be loaded automatically upon
     * class instantiation. These helpers will be available
     * to all other controllers that extend BaseController.
     *
     * @var array
     */
    
protected $helpers = ['array'];


    
/**
     * Template
     *
     * @var \App\Libraries\Template
     */
    
protected $template;


    
/**
     * Constructor.
     */
    
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
    {
        
// Do Not Edit This Line
        
parent::initController($request$response$logger);

        
//--------------------------------------------------------------------
        // Preload any models, libraries, etc, here.
        //--------------------------------------------------------------------
        // E.g.:
        // $this->session = \Config\Services::session();
        
$this->template = new Template;
    }


and your controller extends BaseController
Thanks Matheus Castro. Your explanation is very good.  I will try on it. Do you know about using Third Party?
Reply

#4
(03-07-2020, 03:59 AM)jackylim Wrote: Hi.

 I need some help here. I can't understand how to use helpers, libraries and thirdParty. If anymore can create the sample of source code and share with me? So that I can look at it. Also, how to auto load helpers, libraries and thirdparty if that is possible. Cause I had go thru the document. But I can't understand it.
By "third party" you mean use one or more of your own php classes ?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.