Welcome Guest, Not a member yet? Register   Sign In
Writting support classes?
#11

[eluser]Damien K.[/eluser]
I love how the community jumps onto a thread that I reply to, which initially has 0 replies! Stop picking on me! Wink

Quote:Maybe I’m just lazy, but it becomes cumbersome to manually manage all includes if they are scattered around the code, on single place to manage them, preferably if done automatically, would be better, it’s what I’ve gotten used to and it feels I’m regressing instead of progressing, why should I do something manually, and that can be error prone, if I can create a method that will do that for me?

I bet you're so used to Hibernate or other ORMs/middle-wares, which generate JavaBeans for you without having to 'import' anything (ie, 'include' in PHP terminology). However, no matter how much code-automation you use, you can't get around not importing classes in Java; the same with PHP includes (CI's loading of classes is essentially an 'include'). Furthermore, there is nothing preventing you from creating methods to include your files. The reason why you believe you can't or find it very difficult is because you're very narrow-minded. I get the impression that you are unable to transfer your Java skills into this world of PHP. It is a whole lot easier for you to develop in PHP than a PHP developer to transition to Java -- most fail in their endeavour. You probably need to know more tricks and know-hows of PHP to progress further in any PHP framework and not just CI. You probably need to learn to walk (in PHP) before you learn to run (no offence though).

Quote:
Code:
Here is my simplified MY_Controller.php
It’s basically what I have and it kind of illustrates what I wanted to say, if I’m not mistaken, the MY_Controller is in the libraries folder, yet it is a controller and should be where all controllers are, if you name it otherwise, it will not be loaded by CI or at least will not work correctly, you can’t have

If you insist, you can put MY_Controller with the base class CI's Controller somewhere in the system/libraries folder. Now you won't see it in your application's libraries folder. There, solved! Smile Like what someone else has said, you can change your perception and see it as a controller definition as opposed to an actual controller. Good response!

Quote:
Code:
XPTO extends Controller
and
Code:
XPTO2 extends XPTO

steelaz already proposed a decent solution to this already.

Quote:I have, has they don’t fit the bill. The ContactManager class is model, it contains a linked list of Person objects that are model, each Person contains a Contact that is model but I cannot let CI manage them or it will try to load what it can possibly know how. Toolbar is model, but must not extend from Model, Menu is model but most no extend from Model, they all need to be manually managed by me. Files manually included, some are in the libraries folder, some are in the models folder, yet they all should be considered model, they are the application. They have no view to show their contents, nor a controller as they need none, yet the provide all the functionality of my application, nevertheless CI forces me to separate them in a way that is not natural, considering the problem’s domain.

If you've RTFM, you will know that the model classes goes in the model folder. Smile See how helpful the manual is? I don't think you are require to extend from Model, but I can be wrong. But have you tried not extending Model? Furthermore, you don't even have to name your models, for example, User_model like what the manual said. I just happen to know that because it worked seemlessly for me and I wasn't thinking when I named them. Your inability to comprehend manuals is contagious! That was harsh... and I was j/k. Smile

If my theory is correct, you can put anything in the models folder. CI's way of loading is (surprise!) via 'include'. Sometimes it pays off to dig into the code. Sheesh, all these geeks in the community...

Quote:Everything is in TFM + common sense/intuition + experience.

When I said experience, I meant software design/development experience (which you might have plenty of, but all in Java). It has nothing to do with CI. Think outside the box. Your Java skills are highly transferable. This discussion reminds me of those who swear by VI/Emacs (a tomato smacked right in my forehead). They clearly haven't used Visual Studios before and never will.

I think the bottom line is that you want to see some of the features in Java that is not available in PHP. I have always missed early error catching (think compilation errors) and excellent code-completion when developing in PHP, but my code are so flawless now-a-days that I can make due without them. Smile However, I'm enjoying the time it takes to develop a web application in PHP as opposed to developing in Java/.NET/Perl/Python/RoR. Isn't that the reason why you're here in the first place?
#12

[eluser]Damien K.[/eluser]
Btw, I am NOT a Microsoft employee nor endorse their views, expressed or implied! Wink
#13

[eluser]bretticus[/eluser]
Quote:Hum… so inheriting from a Controller makes my class be.. not a Controller? I know it may not be accessible from an URL, but it is, by definition of inheritance, a Controller, nevertheless, not the point.

This is retarded. I can't believe I'm even posting this! It has nothing to do with inheritance. A controller in the CI framework is an _instantiated_ object. MY_Controller in the library is a class _definition_ (and this model applies to just about every language.) It's appropriate, as a class definition, that this be in a folder called perhaps...libraries?

As you said, not the point. Either way, what a stupid complaint. Quit whining and just use the damned framework (or just quit whining in here.)
#14

[eluser]Knitter[/eluser]
Hibernate does bring back memories Smile, but no, I like to generate things myself. But am I the only one that knows of the __autoload PHP function? http://us2.php.net/manual/en/language.oop5.autoload.php, because that's what autoload means to me. And that also uses includes and there is nothing wrong with includes, I don't like to write them all the time and such but hey!, it is the to bring code from other places in PHP and I live quite well with it.

Well, narrow minded was a first, maybe my communications skills are really going down the drain, it has been some time since I've written something in a forum Smile

I've RTFM, I know what goes where, that is not the problem, the problem has I said in the post before yours is to know if I'm understanding it correctly or if I'm missing something, looks like DMZ was one thing I was missing - did I ever thanked the user that brought that up? - and it also looks like I have to go all the way with the framework changes to get some 'simple' things to work.

And, honestly, what's with the Java thing? I mentioned it in one sentence, one!. Other than that was only as direct response to some question, you're the one gluing me to Java Big Grin. And by god, let PHP be PHP and Java be Java, I don't want Java features in PHP, never even crossed my mind here.

VIm also brings nice feelings to it, VS not really Big Grin, but I'm more of a NetBeans IDE user, from C/C++ to PHP it supports everything Big Grin

OK, if I really sound that Java centric and annoying just because I'm questioning how CI works and trying to push my questions to see how I can work with CI, I'l just stop. I think you'll be happier without someone questioning CI and I'll be better off without trying to convey one idea only to see it be changed to something else, my loss I guess, still...

EDIT...

"whining", I guess today must be one of my days, oh well, thanks for everything, BrianDHall thanks for the reply it did really helped.

Regards,

Knitter
#15

[eluser]Damien K.[/eluser]
@bretticus: I think he's talking in terms of Object-Oriented Design and Analysis, which is perfectly valid. Now that the design part is done, he can start coding and think outside the box. Knitter is just a little too confined in his OO-land. Smile
#16

[eluser]BrianDHall[/eluser]
With some enhanced understanding of what on earth is going wrong with this discussion, I'm returning to the originating post and hope I can clear some things up.

This might be considered a deviation from my earlier post and not be strictly about 'porting', but it reflects newfound understanding.

[quote author="Knitter" date="1254274927"]I'm now trying to get all this into code, so today's question is: Where do I put my application classes and how does CI know about them, or manages them?[/quote]

OK, here is where you start to go wrong. CI is, and this will sound strange, not concerned with your applications classes.

...yes, that sounds weird, but for you and your pre-existing classes its true.

In CI the $this->load functions are all specific to certain CI classes that extend a base class that is part of CI. They instantiate one instance of the thing being loaded and assign it as a member object of the CI super-object for easy reference with $this.

If you want to use your own classes and don't mind that they don't have certain built-in methods, properties, and functions provided by CI then CI doesn't need to get involved at all!

This is a big upside of CI, and it's such a big deal that its hard to realize it - unlike other frameworks and systems, CI does very little and gets out of your way. You can for instance just wrap CI around a complete system and use CI for nothing but routing if you wanted. This allows you to drop in Zend framework library objects for things like flickr or twitter or whatever and CI doesn't seem to mind at all.

If you want certain classes to be autoloaded in the sense you mean it, I have a trick for you. Make a 'library' class as the manual instructs, and autoload it in your config.php file. In that library include whatever you want to include - have it be a script that includes all files in a specified directory, or however you want to handle it! include() menu here, and then anywhere else you should be able to call new Menu($params) and it Just Works.

Also, extending model doesn't actually do very much. If you want to use your own pre-existing model knock yourself out. You can never use a model in CI and it won't complain - you won't even lose any functionality! I really like DMZ and how it handles ORM, and you could still integrate your system with it...but its opinionated in ways that might not work for you. So feel free to just include that non-CI model and load it up and go!

Quote:But CI puts me in the position where I don't really know how to create my application, it tells me that the model is just a collection of classes that only have data, and data access if you considered accessing the DB as part of the model, and that a controller is an all mighty class/entity that controls everything.

I think a lot of MVC talk is phooey, which is why I like CI. It ought not be so damn opinionated, and it actually isn't when used that way.

Controllers and functions are CI's core system, and they control URL routing and program flow. How you work beyond that is up to you entirely. You need never use a CI view or model if you don't want to.

Now, to individual items...

Quote: So:
- How do I access one controller from the other, or, send events to listening controllers?

CI does not offer this or do this. Controllers are to be...well, sort of islands unto themselves, with no direct interaction or co-operation amongst themselves. I often use only 1 controller because I have little reason to split the file up into so many distinct pieces.

The controller in CI just 'controls' what HTTP requests invoke what, and they load up some of the core functionalities of CI and enable its various helper classes and such.

If you don't want to they need do nothing else. If you want your controllers and functions could be little more than routed calls that control the instantiation of certain objects that take it from there.

Quote:- Where do I put my support classes and interfaces and how does CI load them? Must I do all the work myself and go around what CI does?

It really depends. If your existing classes do all the work CI does, then you don't really need CI. Use only what you need like routing if you want, but it becomes debatable if CI is really doing very much for you. Managing the separation and organization of things softly is really most of CI's job as a framework.

Quote:- If, for example, I was building a contacts application I would create the ContactManager class, that would hide all the functionality of my application, I would then create the necessary views to it, can I do something like this in CI, or am I stuck with the "one page-one controller" thing?

Indeed, one-page is one controller, but this is really a semantic issue. CI takes a page and routes it somewhere - it separates things into controllers as "groups of related pages" and functions as the actual pages themselves. The models then handle the data manipulations of the application, and views handle display. That's all - they are very lightweight.

Quote:- Can I have a middle controller from where all my controllers extend without having to modify CI? I have a piece of code that all controllers should have, can I create an abstract controller that is going to be the parent for all my controllers? Or must I use things like URI mapping and extending base classes from CI?

The MY_Controller, as mentioned, is kind of magical in ways and I think this one is one area where the question is answered sufficiently.

Just so you know, I do most of my work in CI with one controller and no MY_controller, as I keep the 'common to all pages' code in the constructor. If my app gets big enough to need splitting into different controllers then to avoid copy/pasting I will use a MY_controller for the universal code.
#17

[eluser]BrianDHall[/eluser]
[quote author="Knitter" date="1254443393"][quote author="BrianDHall" date="1254434442"]It seems to me that you are trying to do a 'port' of your code which already has quite a bit of MVC concepts, but those concepts don't seem to fit how CI works.[/quote]
Yes, that is, sort of what I'm doing, I'm porting an existing project, and the some of the concepts that I have always used and that is not going well Sad.[/quote]

The good news is I actually think the problem is you think CI does more than it really does. Rasmus Lerdorf joked that CI is his favorite framework - and added that many people think it doesn't do enough to be called a framework, and its the lightest of all the frameworks. Thus Ramus concludes he wouldn't mind using it, because he thinks frameworks are inherantly bad and the less of a framework something is then therefore the better it must be Smile

CI seems take this approach. You can think of CI as the router, and it does all this using a front-controller to load up one master CodeIgniter super-object.

However, this object is best though of like a house - you start inside the house, but there is nothing to say that you can't walk right the doorway and step outside into pure PHP in either functional or OOP form. CI won't mind, and sometimes this is Absolutely The Right Way To Do It as CI plays pretty well with Zend libraries, facebook and google APIs, and tons of others. Except for CI's out of the box hatred for GET methods (which is fixable), CI does little to screw with the overall environment.

[quote author="BrianDHall" date="1254434442"]
In short, you need to either port your code and accept that CI does things differently, or setup considerable extensions and customizations to the framework to behave differently than it was designed to behave.[/quote]

Quote:I guess the all point of my post is to really understand if I have to go all that way, is really CI design in such a way that so many changes are needed or am I missing something that would allow me to have what I want without that much work.

Originally I thought you couldn't, but now I think you certainly can.

Quote:
Code:
$user = new User();
$user->usergroup->get();
$user->usergroup->promote('admin');
Now that is great! Thanks for the example and the extension name, I'll really have to have a look at it.

I'm just glad to have a system I can whole-heartedly recommend. I've been given so much bad advice I feel compelled to give what I think at least is good advice Smile

[quote author="BrianDHall" date="1254434442"]
You seem to expect to be able to use your own previously made controllers, models, and views seemlessly or with little effort automagically in CI - all while either wanting CI to use its magic in some instances, but not in others.[/quote]
Quote:Of course I don't really expect to just use my code but would like to understand if CI is that flexible, and by flexible I want to say that it doesn't consume 50% of the projects time.

Again, somehow I adopted the idea that it isn't that flexible, when previous I have made it a point to say that CI IS that flexible, more so than any other system I've seen.

I know think you could just wrap your existing system with little effort and go from there, working from complete system towards using CI for more things as you go. A CI hello world is only about half the speed of a pure php hello world depending on configuration, whereas zend runs at about 1/4 and others run at less than 10% - so you don't have to pay too much in terms of performance to use CI for so little. Some people use CI and Wordpress together and do so happily, never noticing the extra strain of loading two complete systems together.

Quote:Does this forum have any thing like points or something that I can give you? Thanks for the reply it really help me understand what the options are and how I can work my way into getting my projects running on CI. And I'm going to give that DMZ thing a try as it looks it's what I've been looking for. Nevertheless, I think I'm getting the hang of CI.

Regards,

Knitter

I do hope you will find a useful tool in CI and DMZ, and hope this discussion gone-wrong isn't too souring for you. Some days just aren't as bright as others. Smile




Theme © iAndrew 2016 - Forum software by © MyBB