CodeIgniter Forums
Use more PHP standards (namespaces) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Use more PHP standards (namespaces) (/showthread.php?tid=61297)

Pages: 1 2 3


Use more PHP standards (namespaces) - rtorralba - 04-07-2015

Hi,

I completly agree with keep codeigniter simple, but i think some things that codeigniter do can be changed for more standard style.

For example use namespaces instead loader class or core clases overwritting with its prefix defined on the configuration, or codeigniter prefixes (CI_) for not repeat class names.

E.g.

For create a master controller for my app make something like:


PHP Code:
namespace MyApp\Controllers;

class 
MasterController extends CI\Controller 

And then in the final controller:

PHP Code:
use MyApp\Controllers;

class 
ClientController extends MasterController 

And apply this logic to declare and use models instead use a CI_Loader:

PHP Code:
namespace MyApp\Models;

use 
CI\Libraries\DB as DB

class ClientModel extends CI\Model {

 
 public function getRows()
 
 {
 
   return DB::get('clients')->result();
 
 

And then in the controller:

PHP Code:
use MyApp\Models;

$clientModel = new ClientModel();

$clients $clientModel->getRows(); 

And apply this to all codeigniter elements, DB, views...

I think this don't add complexity, don't add orm, template engine, etc... Simply replace codeigniter thought the way to do certain things for php standard way

Greetings.


RE: Use more PHP standards (namespaces) - Renatogarou - 04-08-2015

I agree. Simple, but modern also


RE: Use more PHP standards (namespaces) - gofrendi - 04-08-2015

Good, however this won't be like CI we all know.
I guess the migration will be very hard.


RE: Use more PHP standards (namespaces) - cjj - 04-08-2015

CI is a PHP framework.
CI should be developed along with PHP.


RE: Use more PHP standards (namespaces) - feryardiant - 04-09-2015

I'll miss it
PHP Code:
$this->CI =& get_instance() 



RE: Use more PHP standards (namespaces) - ronelb - 04-09-2015

I support the implementation of namespaces in CI.


RE: Use more PHP standards (namespaces) - mwhitney - 04-13-2015

While I think CI should be namespaced and should recognize application classes which use namespaces, I don't think it should require everyone to completely rewrite their applications to upgrade from CI3 to CI4. There is still room for backwards compatibility while updating the core classes to use and support namespaces.

It could be as simple as use of the loader and/or get_instance() to indicate that CI classes should be available via $this-> for legacy support.


RE: Use more PHP standards (namespaces) - rtorralba - 04-13-2015

(04-13-2015, 10:26 AM)mwhitney Wrote: While I think CI should be namespaced and should recognize application classes which use namespaces, I don't think it should require everyone to completely rewrite their applications to upgrade from CI3 to CI4. There is still room for backwards compatibility while updating the core classes to use and support namespaces.

It could be as simple as use of the loader and/or get_instance() to indicate that CI classes should be available via $this-> for legacy support.


Hi,


I think is not necessary maintain the backward compatibility. Codeigniter has some solutions for deficiencies that php had in the past but not now. For example loader class, for load classes or prefixes use like CI_ to prevent to use same name classes.

This problems are now fixed natively in php, then, is not necessary to add other way to make some things.

In addition to this, ci will be easier to new users that knows only php, because if somebody know php then can understand code like $object = new CI\Models\Client(); but don't understand ci style code like $this->load->('client_model') and he should to learn it.

I think is enough maintain ci3 fixing bugs and possible exploits and make a new version with the same codeigniter simplicity but using native php.

In fact I think modern PHP codeigniter can be easier and simple because all code unnecessary can be deleted making it easier to learn and easier to maintain.

Greetings.


RE: Use more PHP standards (namespaces) - sv3tli0 - 04-14-2015

Not just namespaces .. Traits , interfaces and others must be added to CI.
Even base PHP interfaces and class's as Iterator, ArrayAccess, Serializable, Closure, can be used on some places..

CI must go closer to PHP base practices in OOP programming..


RE: Use more PHP standards (namespaces) - mwhitney - 04-14-2015

(04-13-2015, 02:07 PM)rtorralba Wrote: I think is not necessary maintain the backward compatibility. Codeigniter has some solutions for deficiencies that php had in the past but not now. For example loader class, for load classes or prefixes use like CI_ to prevent to use same name classes.

Short-term backwards compatibility is how any platform maintains its existing user base, whether it is an OS, a programming language, an API, or a framework. Even if it requires an extra compatibility layer, it is usually worth the extra effort to provide an easier upgrade path for existing users.

The reason for this is simple: if I have to rewrite my existing application from scratch to move from CI3 to CI4, I then have one more reason to evaluate other frameworks and one less reason to stay with CI.

Some other PHP frameworks have resisted providing backwards compatibility, and many of them have suffered for it.

(04-13-2015, 02:07 PM)rtorralba Wrote: I think is enough maintain ci3 fixing bugs and possible exploits and make a new version with the same codeigniter simplicity but using native php.

Given that the end-of-life date for CI2 has been set for 6 months from now, I really don't have any faith in the idea of long-term support for an older version of the framework. While the development time of CI3 has been exceptionally long, the maintenance of CI2 during that time has not been stellar, either (though neither is necessarily the fault of the current developers/maintainers).