Welcome Guest, Not a member yet? Register   Sign In
I really think it's time for me to learn a framework... but I've got a few questions
#1

[eluser]ghebert[/eluser]
I'm working on a few big projects, one in particular that has well over 100 tables, most of them with 10,000's of rows and a few with millions of rows. They're not really high-traffic sites (they're mostly intranets), luckily.

Obviously with such large datasets, most queries are highly optimized for their specific usage. Many queries touching the same tables can look really different depending on what columns are being extracted. We also do a lot of reporting, this is another place where tricks are used to gain speed. Since se use all sort of tricks to make them fast, so obviously using the built-in query generators ($this->load() or whatever) would not really be used that much.

How much of a pain is it to build your own queries in many places, and does it defeat the purpose of having a framework? I've looked at CakePHP and while it seems powerful, too much magic is going on. And very often, the tables are already created when I get a project handed over... so convention over configuration would not be really helpful to me (I don't always have the control on the table/field names). This is why I'm very interested by CI.

Anyway I'm simply looking for advice since I'm tired of having 150,000 of lines to manage on that project. Life would be so much easier if we would have a framework!!!!
#2

[eluser]chobo[/eluser]
You can still write queries the way you use to do with php, you don't have to use the active record option CI has; I'm not even sure if that slows things down much, but makes like easier if you switch databases a lot. I suspect the extra overhead of CI won't affect your query speed, since queries would still be executed in exactly the same way as before.

Honestly, maybe I'm missing the boat on something, but I don't think using CI would really affect performance, since your "bottleneck" is just running queries on a large dataset which really doesn't have anything to do with the framework, just make sure to index your queries Smile.
#3

[eluser]Phil Sturgeon[/eluser]
CI should make things any different. Frameworks are usually a little slower than vanilla PHP but that entirely depends on the quality of you original coding!

As chobo has said you wont be required to convert your queries at all. Using the ActiveRecord class is just a way to build strings in a PHP-coder friendly way. Hides the SQL and is easier for noobs.

You will be perfectly fine using $this->db->query('SELECT crazysql queries and whattnot!'); for all your needs. Good luck!
#4

[eluser]ghebert[/eluser]
Out bottleneck is not PHP, it's the execution of the query on the DB server.

Also, we often have pages where users of level A can edit everything, those of level B can see everything, level C can see some things and edit some other things, and level D can see some things. Also, sometimes the same data can be viewed/edited from many different sections in the site.

Is there an advantage of doing this with a framework, for example can we have a "central" point where the code to manage the updates would be?
#5

[eluser]chobo[/eluser]
Your code will probably end up being much more maintainable given that everything else is same. I've started converting the site in my sig to codeigniter and it is much more organized and I'm using the same techniques that I used the first time around, which gives me more time to focus on the design which is lacking Smile. For example I keep all my database requests in models instead of having them scattered around in various places and I can load and call them when I need to, so they are centralized. Views are also centralized and can be called when needed, and even reused.

Some other side effects of picking up a framework like Codeigniter is that you actually learn to program better. There are still a few things that I haven't worked out yet, like unit testing with simpletest and mock objects, but I'll get around to it.

I'm sure you could easily manage to centralize you update code. I'm not sure what's in your update code, but you a lot of options to centralize it in different ways. You could make it into a library, or if it just runs some update queries separate those into models and load when needed.

Hope that helps
#6

[eluser]Rick Jolly[/eluser]
CI doesn't have an Authorization/ACL system, but if you are looking for a good one, you might want to check out the zend framework ACL. Using it with CI is straightforward - just remember to add it to your include path, then require() or include() it.

There are a few things that CI offers that could help simplify your code when using a complicated authorization system:
1) Break your views up into fragments.
What I mean is this: Every part of a view that requires authorization in order to see it or use it could be a seperate view fragment. That view fragment could be loaded by a library that examines the current user's role and decides whether or not to return the fragment for inclusion. An example might be a sidebar view fragement with links only meant for the "admin" role.
2) Use inheritance.
For example, if you have a back-end admin section with several controllers, you could extend an "admin" parent controller that validates the current user within its constructor. No need to do authorization checks everywhere.
#7

[eluser]Phil Sturgeon[/eluser]
I find a nice easy way of doing ACL is to have a database with simple user levels and two hooks. One loaded pre_controller to check login status and redirect elsewhere if not logged in/incorrect permissions, and the other to set some defaults. Then you can just use loads of if(IS_ADMIN) statements in views.

Also have an array in config that allows certain pages to be always allowed. Need to extend the functionality of that to allow roles or more complex settings. Right now it only covers directory/controller/method checks.

A little messy perhaps, my permission library could be improved by taking a few pages from Zends book. If you need something simple though, give that a try.
#8

[eluser]Peter Goodman[/eluser]
Make sure you look at the alternatives to CI, especially the php5 ones:
CakePHP (php4)
PRADO
Zend Framework
Solar Framework
WACT
Mojavi
Symphony
Zephyr
Konstrukt

I say take a look at all the options because CI a a) php4 and way behind the times because of that, and b) not all that well coded or thought out. I find it encourages some of the worst coding practices, it generally goes against MVC, doesn't supply an ORM (this is useful for some projects, not all though). Seriously, check out *all* the alternatives before you make an (un)informed decision!!
#9

[eluser]johnwbaxter[/eluser]
Rick Jolly - Have you got any tips / notes on using Zend auth in CI? I'm very interested in that.

Ghebert - The extra layer of code really isn't going to make a huge amount of difference. As you say, the optimising needs to be done on the DB for maximum performance gain.

What DB are you using? Depending on what you are doing you gotta be doing some clustered indexing there.
#10

[eluser]Rick Jolly[/eluser]
[quote author="audiopleb" date="1187036690"]Rick Jolly - Have you got any tips / notes on using Zend auth in CI? I'm very interested in that.
[/quote]

Well, to integrate with CI:

1) download the zend framework
2) copy the Zend folder from within the "ZendFramework-1.0.1/library/" folder
3) paste the Zend folder anywhere within your application folder (I drop it in the libraries folder)
4) set the include path to the folder in which you put the zend folder. I do this in config.php since that is always loaded. You could also do it in index.php. Example:
Code:
// set include path for zend
ini_set('include_path',ini_get('include_path'). PATH_SEPARATOR . APPPATH . '/libraries/');
5) require and use it. Here is an example to play with. It is almost identical to the first zend acl example in their docs.
Code:
require_once 'Zend/Acl.php';
require_once 'Zend/Acl/Role.php';
require_once 'Zend/Acl/Resource.php';

class SomeController extends Controller {

    function SomeController()
    {
        parent::Controller();        
    }
    
    function index()
    {
        $acl = new Zend_Acl();
        
        $acl->addRole(new Zend_Acl_Role('guest'));
        $acl->addRole(new Zend_Acl_Role('member'));
        $acl->addRole(new Zend_Acl_Role('admin'));
        
        $parents = array('guest', 'member', 'admin');
        
        $acl->addRole(new Zend_Acl_Role('someUser'), $parents);
        
        $acl->add(new Zend_Acl_Resource('someResource'));
        $acl->deny('guest', 'someResource');
        $acl->allow('member', 'someResource');
        
        echo ($acl->isAllowed('someUser', 'someResource') ? 'allowed' : 'denied');
    }
}

This simple ACL example should probably be extracted to a library that you'd load before testing a user for authorization. You can also serialize the ACL object which allows you to update it dynamically in your code.




Theme © iAndrew 2016 - Forum software by © MyBB