Welcome Guest, Not a member yet? Register   Sign In
How do I load code?
#1

[eluser]JasonS[/eluser]
I am creating a basic CMS, it is my first project with code ignitor. So far I really like it. My coding is neater than ever and everything is so easy. However I am now need to leave the comfort of controllers and views and start importing functions.

This is what is I am making.

The user can enter content on the admin side of the website. If the content is standard text this is loaded into an array and is sent to the view page. No problem there.

If the content looks like this...

### Portfolio ###

It will call a function called portfolio.

Now, I am not sure what the other folders are for in my application folder. Would I store the Portfolio function in the libraries folder?

If so what file name do I need to give it?
Do I need a class in the file?
How do I call a function from the library?


My other question is what is the models folder for?
#2

[eluser]Pascal Kriete[/eluser]
Ok, first the folders:
config: configuration files, such as your database configuration.
controllers: you know this one
errors: error templates (like those pretty 404 errors)
helpers: helpers - essentially files containing functions. You could make one of these.
hooks: code that runs at specific points of your application. Don't worry too much about these, they tend to make your code very hard to follow.
language: language files for multi-lingual sites.
libraries: libraries - files containing classes. My suggested solution.
models: models - a way to seperate your database calls from your logic.
views: you know this one as well Smile


Ok, now my suggested solution to your problem:
Code:
class Viewfuncts {

    function portfolio()
    {
        //whatever
    }
    function another()
    {
        //another whatever
    }
}
Drop that into the application/libraries folder in a file called viewfuncts.php, and call $this->load->library('viewfuncts');

Then any function is available through $this->viewfuncts->function_name()

That's the very basic solution. Definitely read through the user guide pages I linked to.
And welcome to the forums.
#3

[eluser]JasonS[/eluser]
Thanks a lot. Thats very informative.




Theme © iAndrew 2016 - Forum software by © MyBB