Welcome Guest, Not a member yet? Register   Sign In
Helpers and Other Conventions
#11

I don't know that the style guide is going to change at this point, honestly. While I didn't write the style guide, I think if you look at PHP's own functions, they're all named snake_case so, to me, it makes sense in that respect.

About namespacing, I'll consider it. I haven't done much work with namespacing and functions, but it seems like then everything gets even wordier? Instead of form_open(), you're now doing we'd have to use \CodeIgniter\Helpers\Forms\form_open(), which is kind of ugly. Smile I suppose we could put "use" statements in the views but that gets even uglier. So, not sure if there's an elegant way to make that work at the moment.
Reply
#12

(This post was last modified: 06-29-2016, 10:59 PM by prezire.)

There's a way to get around that. See my pre PHP7 sample http://icecream.me/2a74daa0983861570d3a50d0d07e4714. For reference, you may refer to http://php.net/manual/en/language.namesp...orting.php and search for "Group use declarations". Hope it helps.

PS: Don't mind the require_once() and stuff Big Grin
Long live CodeIgniter!
Reply
#13

Too many namespaces within 1 framework and its app..
Perhaps all functions should be declared under CodeIgniter namespace only.
Best VPS Hosting : Digital Ocean
Reply
#14

(06-28-2016, 09:06 PM)kilishan Wrote: Here's the styleguide: https://bcit-ci.github.io/CodeIgniter4/c...guide.html

However, we don't have any plans at the moment to convert helpers to static classes. I've always been told that simply shoving a bunch of procedural functions into a class is "doing OOP wrong", so that's where my bias comes from. I will admit the syntax is, in some ways, nicer, and in other ways not to much. I can also see it being problematic with things like the form validation, if it stays anywhere close to how it is, and maybe some other things we have cooking.

(06-29-2016, 11:12 PM)sv3tli0 Wrote: Too many namespaces within 1 framework and its app..
Perhaps all functions should be declared under CodeIgniter namespace only.

I believe the goal is to avoid name conflicts.
Long live CodeIgniter!
Reply
#15

(This post was last modified: 06-30-2016, 12:34 AM by sv3tli0.)

(06-30-2016, 12:11 AM)prezire Wrote: I believe the goal is to avoid name conflicts.

Its good goal but 1 avoid of conflicts should not create others..
Helper is too common word as Config which is used already for namespace.. 
And having CodeIgniter, App, Config, Helper namespaces just within 1 sample app its too much I think..

At least for Functions I don't see any problem to have them just under CodeIgniter namespace. 
Perhaps some system option to alias them into the APP namespace can be helpful.

By the way many calls of USE (in controllers / models / views ) is something common this days. 
My IDE PHPstorm even auto add it at the start of the file when you are using some class/function under some namespace..

So this is the way how PHP is made and developers must accept it I think.
Best VPS Hosting : Digital Ocean
Reply
#16

Without getting hungup on specific names, etc, it sounds like something along the lines of the following might be a good approach. Thoughts?

CodeIgniter3 ... 


system/helpers/url_helper.php
Code:
if ( ! function_exists('site_url'))
{
    function site_url($uri = '', $protocol = NULL)
    {
        return get_instance()->config->site_url($uri, $protocol);
    }
}
...

application/whatever...
Code:
$this->load->helper('url');
echo site_url();

CodeIgniter4?? ...

system/helpers/URL.php
Code:
namespace CodeIgniter\Helpers\URL;

    function siteURL($uri = '', $protocol = NULL)
    {
        return ...
    }
...

application/whatever...
Code:
use CodeIgniter\Helpers\URL;
...
echo URL\siteURL();
James Parry
Project Lead
Reply
#17

(06-29-2016, 06:13 AM)kilishan Wrote:
(06-29-2016, 01:17 AM)Narf Wrote: It's not OOP at all, you're not using objects.
The only reason for that usage is lack of function autoloading.

Sure it is. Classes are objects, and it's got methods. That makes it a (really poorly designed) object, right? Smile But, yes, I know what you mean.

The other valid reason I've heard for doing that is it limits the global function pollution. Neither one of those are good enough reasons for me to consider the change, though.

No ... classes are classes. When you don't instantiate them, there are no objects.
Reply
#18
Thumbs Up 
(This post was last modified: 06-30-2016, 01:48 AM by sv3tli0.)

(06-30-2016, 12:53 AM)jlp Wrote: application/whatever...
Code:
use CodeIgniter\Helpers\URL;
...
echo URL\siteURL();

This is most comfortable way.  Idea

Controller/Model/View there is no difference, such usage is normal for any PHP code..
And there is no reason why namespaces usage shouldn't exists in a view file, at least until this view is a PHP file.
Best VPS Hosting : Digital Ocean
Reply
#19

(This post was last modified: 06-30-2016, 05:27 AM by prezire.)

I like it too. But reserved words are not allowed like below:

PHP Code:
use Helpers\Array;
Array\
elements();
Array\
randomElement(); 

I know you guys can find a way Smile
Long live CodeIgniter!
Reply
#20

(06-30-2016, 05:21 AM)prezire Wrote: I like it too. But reserved words are not allowed like below:

PHP Code:
use Helpers\Array;
Array\
elements();
Array\
randomElement(); 

I know you guys can find a way Smile

The array helpers are useless.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB