Welcome Guest, Not a member yet? Register   Sign In
Hi, need definined a service to work to use from helpers functions
#1
Exclamation 
(This post was last modified: 01-26-2021, 09:42 PM by yuma2020.)

Hi community, need definined a service to work from helpers functions, I would appreciate it if you would kindly excuse my ignorance, as I find myself facing a world of change, it really is all so strange. In this case I'm working on some great helpers, but I'm faced with a matter of requiring a primitive library from a primitive and my great helper.

I require a simple function, but this requires making a primitive called, from the primitive Codeigniter 3 calls to a primitive algoritme library as we see it is a simple as stupid as performing or similar call.

PHP Code:
$CI->load->library('get_primitive_library'); 

I don't think it's code morse, just because I don't understand the documentation correctly, maybe I don't know too much, maybe I'm not deciphering the morse code from the document.

I'm just maybe totally wrong, because you'll see another more experienced programmer who has generated 4 aircraft for Nasa, but this thing is just one thing I wonder, like defining a service that in my opinion would be a way to solve that situation, because in the documentation they don't talk about calls to the library from something called "Helper".
the syntax is not impossible to understand, what may not be understood is to say that "Helper" needs to call library to perform some hairy actions defined in a lot of great classes that exist of infinite and extremely advanced possibilities within primitive Libreries that are requeriable from a view or controller. But the helpers as they call a library?

Excuse me if my language is not the best, it is simply that I am too good to understand, but the lack of explained documentation and/or primitive examples of how to perform a primitive integration are not entirely clear.


Perhaps some over-the-box programming experts will say, "You have to create an instance within a service," now I wonder how to build that instance to solve a hairy problem within a cool primitive helper that requires functions to process from a library.

I hope you understand, it is a constructive criticism totally seen from the reasoning of a Codeigniter 3 developer that some things were as many say "more professional and some were not". While many of us understand that the new things in Codeigniter 4 are superior, but there are simple things that are not possible to do, or maybe I'm wrong and they're not as easy as they used to be.

a simple CI->load->library is now a bunch of functions and calls and configurations that may make the ship faster to conquer the potato you need to make?.

I don't stray to anything, maybe it's a tremendous device to write this, maybe you're right know, excuse me in case I'd like to know, know and/or understand if it's okay, that it's wrong, like acquiring this something, like answering call CI->load. I hope you understand what I'm requiring and understand how to explain how to create a service and how to consume a library from an helper if possible
Reply
#2

You can load any of CodeIgniter 4 libraries in a help by calling there service.

Example:

PHP Code:
$request Services::request();
$uri     $request->uri

You can load a help within a help.

Example:

PHP Code:
helper('text'); 

If it is a custom libraries just create a service for it or autoload it in the autoloader.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 01-26-2021, 10:02 PM by yuma2020.)

(01-26-2021, 09:55 PM)InsiteFX Wrote: You can load any of CodeIgniter 4 libraries in a help by calling there service.

Example:

PHP Code:
$request Services::request();
$uri     $request->uri

You can load a help within a help.

Example:

PHP Code:
helper('text'); 

If it is a custom libraries just create a service for it or autoload it in the autoloader.

Great now if I like to make a call to a default library now, how to call a custom library created by me in the folder "Libreries"?

Please community, need call a primitive library custom not is default.
PHP Code:
<?PHP
namespace App\Libraries;
/**
 * Common - A helper class to process Common strings.
 *
 * @author Villalba Juan Manuel - https://www.hexomedesarrollos.com/
 * Date: sunday 24/01/2021
 *
 */
class CommonLibrary
{
    public function get_PortfolioCategory()
    {
        // start script
        $portfolio getTable('portfolio_category');
        return $portfolio;
    }

    public function  check_CategoryPortfolio()
    {
     
// some flow data ...
    }


Reply
#4

(This post was last modified: 01-27-2021, 02:28 AM by InsiteFX.)

Just use include and then new on the library, or autoload it.

Read this.

Defining Services
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

Hi

To call a function of CommonLibrary class from the \App\Libraries namespace in any place of youre code, Helper or Controller or some else Library:

PHP Code:
$cmn = new \App\Libraries\CommonLibrary();

$portfolio $cmn->get_PortfolioCategory(); 

It's enough...
No need to include any files and define services
Reply
#6

(This post was last modified: 01-27-2021, 08:54 AM by yuma2020.)

(01-27-2021, 05:22 AM)vitnibel Wrote: Hi

To call a function of CommonLibrary class from the \App\Libraries namespace in any place of youre code, Helper or Controller or some else Library:

PHP Code:
$cmn = new \App\Libraries\CommonLibrary();

$portfolio $cmn->get_PortfolioCategory(); 

It's enough...
No need to include any files and define services


You're right, aller doing some tests the eh constado, I would just like to be added to the documentation as well.
There are also things that I think are strange, define a service, you are supposed to define it in "Config" folder, but it would not be better to have a folder called "Services", so that sorting it will be more simplified.
I would like to know some example of implementation by applying a specific folder that is called "Services" in the "App" folder, since thank you very much and excuse my expressions, it is simply that I am new and I am recently discovering the generosities of Codeigniter 4.
[Image: 1-24o-Tbi-r9-SXkk-Jjt-V2-B2-A.png]
It would also be great to be told is the goal and examples of how it will stop me in the development of my small cloud to operate in production, always talking about that of codeigniter 4 services.
Reply
#7

(This post was last modified: 01-27-2021, 02:56 PM by InsiteFX.)

Services allow you to later change the library in one place instead of making the library
change in every file that you call that library in.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

(01-27-2021, 12:12 PM)InsiteFX Wrote: Services allow you to later change the library in one place instead of making the library
change in every file that you call that library in.
It's great, I'd appreciate some guidance to explore those alternatives for defining calls. Thank you for the excellent explanation
Reply
#9

You can read about services here.

CodeIgniter 4 User Guide - Services
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB