Welcome Guest, Not a member yet? Register   Sign In
Creating and using libraries

[eluser]Colin Williams[/eluser]
__autoload() is PHP 5 only, and CI aims to be PHP 4 compatible.

CI also has a load_class() method that works like including. It expects the class follows the conventions of a library, and you can pass a second argument of TRUE or FALSE depending on whether or not you want to instantiate the class.

public function  __construct() {
        $barra = array();
        load_class('Menu', FALSE);
        $barra[] = new Menu('Início', 'inicio', false);
        $barra[] = new Menu('Automóveis', 'automoveis', false);
        $barra[] = new Menu('Eventos', 'eventos', false);

[eluser]Damien K.[/eluser]
This is a little off topic...

I don't know who InsiteFX was referring to, but I second the fact that BrainDHall is one of the most helpful users here. I, on second, is not the most helpful user here because I strategically pick the topics I respond to. The reason why both of your original topics got a response from myself was because it had 0 replies. If I did not reply to your topics, it could have been left unanswered. Clearly, you're not showing appreciation for someone to take their time to give you a response. Furthermore, you clearly will not accept other's point of view hence why you are so frustrated. You need to chill a bit. It is better to have someone on the forum to inform you (of how wrong or right) your design is than if it had came from your boss or client. Many of the users who responded to your posts are "gurus" in this world. I am not. I only have ~1 month of experience. Apparently, it didn't matter who the answer came from. Moreover, one does not need to know your project to comment on design (think Software Architect).

You are probably upset because I kept referring you to the manual via 'RTFM'. You said in the other topic that you've read everything and all, but it is clear that you did not or did not comprehend it if you did. Admit it and get on with life. Maybe you're an old developer who resists change or a young developer who thinks he/she is a hot shot... I know, you're neither of those, right? Feel free to prove it with intelligent responses.

No need to flame me more (or thank me); nevertheless, the discussions in both of your topics were very amusing all day.

You should not hesitate to continue to participate in this forum because of a few (err..one) bad apple. If you were to go over all the responses in this forum, almost all of them are genuine and indeed very helpful.

Okay, maybe two bad apples. Personally, I didn't care for your attitude. It appeared to me that people were taking the time to give you good advice and you quickly discounted it or argued with it. I apologize for giving you a hard time but know that your good attitude also counts. Especially when you are asking for people to help you. That said...

Here is a way to use __autoload() in codeigniter. It's a simple hack but it complies with the Codeigniter framework standard (well not the php4 compatibility issue but most people should not have to use PHP4 anymore) and should work the way you'd prefer it to work.

This is done using plugin support for CI.

1. Create an autolib folder (or your preferred name) under application/.

2. Add autoload_pi.php to your system/plugins folder.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function __autoload($class_name) {
    $path = APPPATH . 'autolib/' . $class_name . '.php';
    if ( file_exists($path) )
        require_once $path;

3. Add your Menu class to application/autolib. Name it Menu.php.

4. Add autoload to plugins under application/config/autoload.php.

| -------------------------------------------------------------------
|  Auto-load Plugins
| -------------------------------------------------------------------
| Prototype:
|    $autoload['plugin'] = array('captcha', 'js_calendar');

$autoload['plugin'] = array('autoload');

5. Call $menu = new Menu(); anywhere in codeigniter and instantiate as many times as you'd like.

Just to put an end to this all thing. I don't consider the forum to be bad, I've been reading it for quite some time and thought I haven't participated much, I know what it can offer. I'm also used to forums and all this misunderstandings, which I thing is what this all mess is about, a big misunderstanding.

I call this a misunderstanding because I was never frustrated, or discarded other user's views, sorry if it looked like it, but no, I honestly considered every one's view and looked at it in an objective way, considering the little I knew about CI and the requirements I had, what I wanted to do. I regret not being able to convey my thoughts and doubts about what some issues.

As for attitude, I tried to be as clear as possible, but I can see I failed to do so... and why would I be upset about getting an RTFM answer? It's a perfectly valid answer, no problem about it Smile. Alas I don't think proving myself is really necessary/good, I have nothing to prove, and I'm actually both, an old and a new developer, it really depends on the way you look at it, no intelligent response to give.

I've actually tried that the first time, but I had been messing with CI's code so much that I broke it when adding that code, I had to start with a new CI installation but it's basically the setup I now have.

Considering my experience in writing in the forum, I will expect some misunderstandings on what I've written, but the issue is behind me, as for continuing in the forum, maybe not a good idea, if a few users couldn't understand that I was writing in a calm, interested way, and was really discussing their ideas as valid and important ones, it's better I don't try with the rest of the forum.



Theme © iAndrew 2016 - Forum software by © MyBB